SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old November 25th, 2016, 03:51 AM
Gukupozu Gukupozu is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Nov 2016
Posts: 1 Gukupozu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 25 m 37 sec
Reputation Power: 0
Post Doubling of rows

Hello,
to some of you this question is simple to answer. For me it took some time of watching YouTube, learning in internet and still got no answer to this.

Lets say I have data in Table_X:

Client_id Voucher_type Amount Activity
1 IP4 15 (blank)
1 M20 100 US
1 M01 12 (blank)




And I want to get this from my excel query everything in one row:

Client_id Amount_M20 Amount_IP4 Activity
1 100 15 US


My query is this:

Code:
SELECT 
Client_id,
SUM ( CASE WHEN (Voucher_type = 'M20')
THEN Amount
ELSE 0
END) AS "Amount_M20",
SUM ( CASE WHEN (Voucher_type = 'IP4')
THEN Amount
ELSE 0
END) AS "Amount_IP4",
Activity
FROM TABLE_X
WHERE Activity IS NOT NULL


And Output is missing IP4 calculation, because of Where condition:

Client_id Amount_M20 Amount_IP4 Activity
1 100 0 US


But if I remove Where condition, then I get doubling of rows and this is far away from my desired output.

Client_id Amount_M20 Amount_IP4 Activity
1 100 0 US
1 (blank) 15 (blank)


I would appreciate for any help.

Last edited by Gukupozu : November 25th, 2016 at 03:54 AM.

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Doubling of rows


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap