Return-Path: X-Original-To: apmail-hive-user-archive@www.apache.org Delivered-To: apmail-hive-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4CBFDD14B for ; Tue, 30 Oct 2012 13:58:13 +0000 (UTC) Received: (qmail 55791 invoked by uid 500); 30 Oct 2012 13:58:12 -0000 Delivered-To: apmail-hive-user-archive@hive.apache.org Received: (qmail 55630 invoked by uid 500); 30 Oct 2012 13:58:11 -0000 Mailing-List: contact user-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hive.apache.org Delivered-To: mailing list user@hive.apache.org Received: (qmail 55605 invoked by uid 99); 30 Oct 2012 13:58:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2012 13:58:10 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of john.meagher@gmail.com designates 209.85.223.176 as permitted sender) Received: from [209.85.223.176] (HELO mail-ie0-f176.google.com) (209.85.223.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2012 13:58:03 +0000 Received: by mail-ie0-f176.google.com with SMTP id k11so442874iea.35 for ; Tue, 30 Oct 2012 06:57:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=AcDLRKfC3ygUN2llZ99l3BrUa/ghTK//JWRKo7o6DXk=; b=JXcVWIm+mTcZGbG3szBoYGE1Cgj5U3gWin9PS44DenKOr0V/25Cpms/OxXTDqqmDtG RYSIQxeY6NhAy6ypRrn8pFSXV3x+LmBFvOLOm4mCSWa9yuYn0ouR6EKGb1S4AX84OLYK /76fhH1pruPBW9aHW6jkrVGwjhzprrjEKMVlcEClbFx+FtjsaI++peviP5wOL2OOvIpJ stkqzWywdrnnw/ogGFd1NR+i7IOvyKvSKWkLbbgOYx7kg/zkYhhxLNOkt/jXs3HTknc2 eMKW222C6/bL0tkvM9SUAP1Z2KfxtqkxTtN71LAWGbBVjB09WDu+WlXXmznQpJ93la5g zCAQ== MIME-Version: 1.0 Received: by 10.50.1.170 with SMTP id 10mr1564020ign.2.1351605461755; Tue, 30 Oct 2012 06:57:41 -0700 (PDT) Received: by 10.42.214.14 with HTTP; Tue, 30 Oct 2012 06:57:41 -0700 (PDT) In-Reply-To: References: Date: Tue, 30 Oct 2012 09:57:41 -0400 Message-ID: Subject: Re: Help in hive query From: John Meagher To: user@hive.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org The WHERE part in the approvals can be moved up to be an IF in the SELECT... SELECT client_id,receive_dd,receive_hh, receive_hh+1, COUNT(1) AS transaction_count, SUM( IF ( response=00, 1, 0) ) AS approval_count, SUM( IF ( response=00, 1, 0) ) / COUNT(1) * 100 AS percent FROM sale_test group by fdc_client_id,receive_dd,receive_hh,receive_hh+1; On Tue, Oct 30, 2012 at 1:51 AM, dyuti a wrote: > Hi All, > > I want to perform (No.of .approvals in an hour/No.of transactions in that > hour)*100. > > //COUNT(1) AS cnt gives total transactions in an hour > SELECT client_id,receive_dd,receive_hh,receive_hh+1,COUNT(1) AS cnt FROM > sale_test group by fdc_client_id,receive_dd,receive_hh,receive_hh+1; > > GETREGREOS 23 16 17 5969 > GETREGREOS 23 21 22 2602 > GETREGREOS 24 3 4 114 > > //Approved transactions where response=00 > SELECT client_id,receive_dd,receive_hh,receive_hh+1,COUNT(1) AS cnt FROM > sale_test where response=00 group by > client_id,receive_dd,receive_hh,receive_hh+1; > GETREGREOS 23 16 17 5775 > GETREGREOS 23 21 22 2515 > GETREGREOS 24 3 4 103 > > > I want to perform 100 * (5775/5969) , 100 * (2515/2602) , 100 * (103/114) > like the same for all other clients for each hour i.e., (No.of .approvals in > an hour/No.of transactions in that hour)*100. > > Please help me out as how to achieve this in hive. > > > Thanks & Regards, > dti