Help with SQL Query -
i work mysql not sure how query work on sql.
i have 3 tables:
table1 odbc_order_line_all
this contains order_line_nett_total , order_line_order_id
table 2 odbc_order_all
this contains order_id , order_account_id
table 3 odbc_account
this contains account_accid , other information on account may need in future, hence why adding it.
i joining table 1,2,3 using above constraints.
what want able generate sales report of spend showing account number , total spend can't seem syntax correct.
any appreciated.
here tables:
odbc_order_line_all
order_line_id
order_line_order_id
order_line_date
order_line_mediacode
order_line_source
order_line_product_id
order_line_product_code
order_line_product_name
order_line_quantity
order_line_nett_price
order_line_vat_code
order_line_vat_rate
order_line_vat
order_line_nett_total
order_line_vat_total
order_line_gross_total
order_line_unit_cost
order_line_cost_currency
order_line_cost_exchange_rate
order_line_type
order_line_stage
order_line_stage_date
order_line_invoice_id
order_line_invoice_date
order_line_kit_component
order_line_kit_line_id
order_line_user
odbc_order_all
order_id
order_type
order_media_code_id
order_media_code
order_media_subcode
order_taken_by
order_date
order_account_id
order_delivery_account_id
order_source_id
order_source
order_web_order_id
order_multi_client_id
order_multi_client
odbc_account
account_accid
account_acc_type
account_ref
account_title
account_forename
account_surname
account_company_name
account_house_name
account_add1
account_add2
account_add3
account_add4
account_postcode
account_country
account_phone1
account_phone2
account_fax1
account_fax2
account_email
account_website
account_pricelist_id
account_mediacampaign_id
account_created_date
assuming table names 'table 1' odbc_order_line_all, 'table 2' odbc_order_all, 'table 3' odbc_account, need join 3 tables on relevant joining columns, , sum order line nett total entries each account:
select a.account_accid, sum(l.order_line_nett_total) totalspend odbc_account join odbc_order_all o on a.account_acc_id = o.order_account_id join odbc_order_line_all l on o.order_id = l.order_line_order_id group a.account_accid; however, while there nothing account_accid selected odbc_account, there no actual need select odbc_account table; can join 2 tables, yielding simpler query:
select o.order_account_id acount_accid, sum(l.order_line_nett_total) totalspend odbc_order_all o on a.account_acc_id = o.order_account_id join odbc_order_line_all l on o.order_id = l.order_line_order_id group account_accid; there nothing here different in mysql other sql dbms, knowledge of mysql should transfer directly.
Comments
Post a Comment