Common Use SQL

Common Use SQL

Structured Query Language (SQL) is a computer language that helps you interact with databases. Here you can find common use SQL statements that you can use when querying the data.



Query 1: Aggregate Store Sales

This 'SELECT' statement will aggregate the Store Sales data and show the respective sums between Walmart Year Week Number 202340 and 202400 by wm_item_nbr, svc_chnl_nm, wm_yr_wk_nbr, vendor_nbr, vendor_nm, store_nbr.

SELECT wm_item_nbr, svc_chnl_nm, wm_yr_wk_nbr, vendor_nbr, vendor_nm, store_nbr, sum(ty_sales_amt) as ty_sales_amt, sum(ly_sales_amt) as ly_sales_amt, sum(ty_qty) as ty_qty, sum(ly_qty) as ly_qty, sum(ty_aur) as ty_aur, sum(ly_aur) as ly_aur, sum(ly_scan_cnt) as ly_scan_cnt, sum(ty_scan_cnt) as ty_scan_cnt
from wmt-dv-bi-link-prod.dv_supplier.store_sales
where wm_yr_wk_nbr between 202340 and 202400
group by wm_item_nbr, svc_chnl_nm, wm_yr_wk_nbr, vendor_nbr, vendor_nm, store_nbr, vendor_nm;



Query 2: Join Store Item Measures, Store Sales, and Store Dimensions

This query joins Store Item Measures, Store Sales, and Store Dimensions data to get a more comprehensive view of store metrics between 202350 and 202400.

SELECT sum(ty_in_trnst_qty) as ty_in_trnst_qty, sum(ty_in_trnst_cost_amt) as ty_in_trnst_cost_amt, sum(ty_in_whse_qty) as ty_in_whse_qty, storeitem.wm_item_nbr
from wmt-dv-bi-link-prod.dv_supplier.store_invt storeitem
join wmt-dv-bi-link-prod.dv_supplier.store_sales storesales
on storeitem.bus_dt = storesales.bus_dt and storeitem.store_nbr = storesales.store_nbr and storeitem.wm_item_nbr = storesales.wm_item_nbr
join wmt-dv-bi-link-prod.dv_supplier.store_dim storedim on storedim.store_nbr = storeitem.store_nbr
where storesales.wm_yr_wk_nbr between 202350 and 202400
group by storeitem.wm_item_nbr





Disclaimer

Your use of API documentation is at your own discretion and risk. To the maximum extent permitted by law, the APIs, documentation and all related software, components, and support are provided by Walmart on an ‘as-is’ and ‘as available’ basis without any warranties of any kind, and Walmart expressly disclaims any and all express and implied warranties, including, but not limited to, warranties of merchantability, fitness for a particular purpose, title, non-infringement, non-interference, and warranties arising from a course of dealing. You acknowledge that Walmart does not warrant that the APIs will be uninterrupted, timely, secure, or error-free. Walmart may modify and delete API documentation in its sole discretion and without notice.


In no event shall Walmart be liable to you or any third parties for any damages whatsoever, including, without limitation, those resulting from loss of use, damage to your computer system, loss of data or profits, or any liability arising out of or in connection with the use of the APIs, documentation, software, components, or support.



©️Walmart | All Rights Reserved | Confidential