Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

if statement - MySQL - subtracting certain rows of a table and presenting the results alongside other rows -


i have been struggling getting query right hours now. have huge amount of data , want show departments ids 10,15,18 , 25. here, want subtract profits each dept id 18 15, i.e. 15-18.

i filter data following query:

select * depttable id in(10,15,18,25) , date = '2009-01-25'

dept ---------- date ---------------- id ----------------- profit
uk ---------- 2009-01-25 ---------- 10 ---------------- 2000
brazil ------- 2009-01-25 ---------- 10 ---------------- 1300
japan------- 2009-01-25 --------- 10 ---------------- 2500
spain------- 2009-01-25 ---------- 10 ---------------- 3200
uk ---------- 2009-01-25 ---------- 15 ---------------- 4000
brazil ------- 2009-01-25 ---------- 15 ---------------- 1700
japan------- 2009-01-25 ---------- 15 ---------------- 3500
spain-------- 2009-01-25 ---------- 15 --------------- 1200
uk ---------- 2009-01-25 ---------- 18 ---------------- 2500
brazil ------- 2009-01-25 ---------- 18 ---------------- 1300
japan------- 2009-01-25 --------- 18 ---------------- 2120
spain------- 2009-01-25 ---------- 18 ---------------- 800

uk ---------- 2009-01-25 ---------- 25 ---------------- 3000
brazil ------- 2009-01-25 ---------- 25 ---------------- 1850
japan------- 2009-01-25 --------- 25 ---------------- 1580
spain-------- 2009-01-25 ---------- 25 --------------- 1070

what want subtract each row id 18 rows id 15. taking uk example:

4000 - 2500 = 1500, doing rest of dept regions give desired result is:

dept ---------- date ---------------- id ----------------- profit
uk ---------- 2009-01-25 ---------- 10 ---------------- 2000
brazil ------- 2009-01-25 ---------- 10 ---------------- 1300
japan------- 2009-01-25 --------- 10 ----------------- 2500
spain------- 2009-01-25 ---------- 10 ---------------- 3200
uk ---------- 2009-01-25 ---------- 15-18 ------------ 1500
brazil ------- 2009-01-25 ---------- 15-18 ------------ 400
japan------- 2009-01-25 ---------- 15-18 ----------- 1380
spain-------- 2009-01-25 ---------- 15-18 ----------- 400

uk ---------- 2009-01-25 ---------- 25 ---------------- 3000
brazil ------- 2009-01-25 ---------- 25 ---------------- 1850
japan------- 2009-01-25 ---------- 25 ---------------- 1580
spain-------- 2009-01-25 ---------- 25 --------------- 1070

2 points:
1. calculated rows id column doesn't have read '15-18', i've typed '15-18' explain issue
2. italics/bold calculated rows, other rows remain same

surely possible?

thanks,

i think work...

select a.dept, a.date, if(a.id=15,'15-18',a.id) id, if(b.profit null,a.profit,a.profit-b.profit) profit depttable  left join depttable b on a.id=15 , b.id=18 , a.dept=b.dept a.id in(10,15,25) , a.date = '2009-01-25'  

tested result:

+--------+------------+-------+--------+ | dept   | date       | id    | profit | +--------+------------+-------+--------+ | uk     | 2009-01-25 | 10    |   2000 | | brazil | 2009-01-25 | 10    |   1300 | | japan  | 2009-01-25 | 10    |   2500 | | spain  | 2009-01-25 | 10    |   3200 | | uk     | 2009-01-25 | 15-18 |   1500 | | brazil | 2009-01-25 | 15-18 |    400 | | japan  | 2009-01-25 | 15-18 |   1380 | | spain  | 2009-01-25 | 15-18 |    400 | | uk     | 2009-01-25 | 25    |   3000 | | brazil | 2009-01-25 | 25    |   1850 | | japan  | 2009-01-25 | 25    |   1580 | | spain  | 2009-01-25 | 25    |   1070 | +--------+------------+-------+--------+ 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -