Home > database >  SQL based on a column of figures for other two columns together
SQL based on a column of figures for other two columns together

Time:10-07

18 18 P00481708010002
P00481708010002 20 20




According to the P00481708010002 number above the raw data
Finally become
P00481708010002 38 38
P00481708010002 38 38

To ensure that there are two data cannot be integrated into a data!!!!!!!!!!!!!!! Only the amount change into 38



The original code
The SELECT cyhq_u_orderdish. Ch_branchno as' name ', -- -- name
T_hq_branch_info vch_company,
. - (select t_hq_branch_info vch_company from t_hq_branch_info) as the 'name',
Cyhq_u_orderdish. Ch_payno as' statement no. '
Cyhq_u_orderdish ch_billno as' order number, number - order
Cyhq_u_orderdish. Ch_dishno as' product code, -- -- product code
(SELECT vch_dishname FROM cybr_bt_dish WHERE ch_dishno=cyhq_u_orderdish. Ch_dishno) as' name '-- name cyhq_u_orderdish. Num_price_org - the convert (a decimal (10, 2), cyhq_u_orderdish. Num_price_org + num_price_add - 1.0/100 (cyhq_u_orderdish. Int_discount * * (cyhq_u_orderdish. Num_price_org + num_price_add)))) as' actual amount, cyhq_u_orderdish. Num_price_org as' sales amount,
Convert (a decimal (1, 2), cyhq_u_orderdish. Num_price_org + num_price_add - 1.0/100 (cyhq_u_orderdish. Int_discount * * (cyhq_u_orderdish. Num_price_org + num_price_add))) as' discount amount,
Cyhq_u_orderdish. Num_price_add as' mark-up '
The from cyhq_u_orderdish left join t_hq_branch_info on t_hq_branch_info. Ch_branchno=cyhq_u_orderdish. Ch_branchno
Where cyhq_u_orderdish. Ch_payno='P00481708010002'






The cyhq_u_orderdish ch_payno is P00481708010002 cyhq_u_orderdish. Num_price_org is the first line the 18 of 20



CodePudding user response:

Is added between the column?
 select field 1 + 2 as field 1, 2 + field 1 as field from table 2 

CodePudding user response:

Is sum up and down, not horizontally

CodePudding user response:

Col1, col2, col3
P00481708010002, 18, 19
P00481708010002, 20, 20


The select table1. Col1 v.c ol2, v.c ol3
The from table1 inner join (select col1, sum (col2) as c2, sum (col3) as c3 from table1 group by col1) v on table1. The col1=v.c ol1

CodePudding user response:

Xiazisr
Junction post rate: 0%

reference
after your questions answered please post.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html

8, how to give points and knot stick?
http://bbs.csdn.net/help#post_dispose
  • Related