mysql Case關鍵字 使用的例項

2021-04-21 02:28:26 字數 4634 閱讀 2942

$sql = 'select'

. ' t1.orders_date as orders_date'

. ' t1.customers_id as customers_id'

. ' t1.billaddress_company as billaddress_company'

. ' t1.billaddress_street as billaddress_street'

. ' t1.billaddress_suburb as billaddress_suburb'

. ' t1.billaddress_city as billaddress_city'

. ' t1.billaddress_state as billaddress_state'

. ' t1.billaddress_country_name as billaddress_country_name'

. ' t1.billaddress_postcode as billaddress_postcode'

. ' t1.shipaddress_company as shipaddress_company'

. ' t1.shipaddress_street as shipaddress_street'

. ' t1.shipaddress_suburb as shipaddress_suburb'

. ' t1.shipaddress_city as shipaddress_city'

. ' t1.shipaddress_state as shipaddress_state'

. ' t1.shipaddress_country_name as shipaddress_country_name'

. ' t1.shipaddress_postcode as shipaddress_postcode'

. ' t1.duedate as duedate'

. ' t1.servicedate as servicedate'

. ' t1.fob as fob'

. ' t1.ponumber as ponumber'

. ' t1.tax1total as tax1total'

. ' t1.tax2total as tax2total'

. ' t1.exchangerate as exchangerate'

. ' t1.purchaseorder_status as purchaseorder_status'

. ' t1.orders_payflag as orders_payflag'

. ' t1.orders_shipflag as orders_shipflag'

. ' t1.payment_id as payment_id'

. ' t1.shipping_id as shipping_id'

. ' t1.shipping_no as shipping_no'

. ' t1.shipping_cost as shipping_cost'

. ' t1.orders_date_ended as orders_date_ended'

. ' t1.orders_back as orders_back'

. ' t1.products_score as products_score'

. ' t1.products_content as products_content'

. ' t1.orders_comments as orders_comments'

. ' t1.update_date_time as update_date_time'

. ' t1.orders_year as orders_year'

. ' t3.customers_id as customers_id'

. ' t3.customers_gander as customers_gander'

. ' t3.customers_firstname as customers_firstname'

. ' t3.customers_middlename as customers_middlename'

. ' t3.customers_lastname as customers_lastname'

. ' t3.customers_company as customers_company'

. ' t3.shipping_id as shipping_id'

. ' t3.customers_telephone as customers_telephone'

. ' t3.customers_email as customers_email'

. ' t3.customers_fax as customers_fax'

. ' t3.customers_credit as customers_credit'

. ' t3.customers_type as customers_type'

. ' t3.customers_role as customers_role'

. ' t2.ordertotal as ordertotal'

. ' t4.tax1rate as tax1rate'

. ' t4.tax2rate as tax2rate'

. ' t4.istax1exempt as istax1exempt'

. ' t4.istax2exempt as istax2exempt'

. ' t4.ispiggybackrate as ispiggybackrate'

. " case when istax1exempt = '0'"

. ' then tax1rate'

. " else '0'"

. ' end as tax1'

. " case when istax2exempt = '0'"

. ' then tax2rate'

. " else '0'"

. ' end as tax2'

. " case when istax1exempt = '0'"

. ' then (tax1rate * ordertotal)'

. " else '0' end as gst"

. " case when istax2exempt = '0'"

. " then case when (ispiggybackrate = '1' and istax1exempt = '0')"

. ' then (tax2rate * ((1 + tax1rate)* ordertotal))'

. ' else (tax2rate * ordertotal)'

. ' end'

. " else '0'"

. ' end as ont'

. " case when istax1exempt = '0' and istax2exempt = '0'"

. " then case when ispiggybackrate = '0'"

. ' then ((tax1rate + tax2rate) * ordertotal)'

. ' else ((tax1rate * ordertotal) + tax2rate *((1+tax1rate )* ordertotal))'

. ' end'

. " when istax1exempt = '0' and istax2exempt = '1'"

. ' then (tax1rate * ordertotal)'

. " when istax1exempt = '1' and istax2exempt = '0'"

. ' then (tax2rate * ordertotal)'

. " when istax1exempt = '1' and istax2exempt = '1'"

. " then '0'"

. ' end as taxtotal'

. ' from orders as t1'

. ' left join'

. ' ('

. ' select'

. ' orders_year'

. ' orders_num'

. ' sum(final_price * orders_products.orders_quantity) as ordertotal'

. ' from orders_products'

. ' where concat(orders_year, orders_num) ='

. $porderid

. ' ) as t2'

. ' on (t1.orders_num = t2.orders_num and t1.orders_year = t2.orders_year)'

. ' left join customers as t3'

. ' on t1.customers_id = t3.customers_id'

. ' left join tax_rate as t4'

. ' on t1.shipaddress_state = t4.zone_id'

. ' where concat(t1.orders_year, t1.orders_num) ='

. $porderid;

return $sql;

this關鍵字使用

一,表示類中屬性 1,沒有使用this的情況 class person public string getinfo public class thisdemo01 執行結果 姓名 null,年齡 0 可以得出結論 此時並沒有正確將內容賦給屬性 假設身邊有乙隻筆,遠處也有乙隻筆,肯定會就近拿身邊的筆。...

this關鍵字的使用

我們曾經曰 起名字要做到見名知意。this 是當前類的物件引用。簡單的記,它就代表當前類的乙個物件。注意 誰呼叫這個方法,在該方法內部的this就代表誰。this的場景 解決區域性變數隱藏成員變數 定義學生類 class student 姓名設定值 public void setname strin...

this關鍵字的使用

1 this可以用來修飾屬性 方法 構造器 2 this修飾屬性和方法 this理解為當前物件或當前正在建立的物件 構造器中的this 在類的方法中,我們可以使用 this.屬性 或 this.方法 的方式,呼叫當前屬性或方法。但是,通常情況下,我們都選擇省略 this.特殊情況下,如果方法的形參和...