To learn how to connect python to Microsoft SQL Server please refer to below blog:
Now we will write a python code to connect to AdwentureWorksDW database stored in Microsoft SQL server. The sql query for the same is as follows: Since ProductCategory is the parent for ProductSubCategory so we will take the sum of SalesAmount based on ProductSubCategory with a column giving the value of parent field ProductCategory. So, the first step is to write a sql query that can fetch the sum of SalesAmount based on ProductSubCategory and ProductCategory. The join between DimProductSubCategory and DimProductCategory can be made using field ProductCategoryKey. The join between DimProduct and DimProductSubCategory can be made using field ProductSubcategoryKey. The join between FactInternetSales and DimProduct can be made using field ProductKey. The Data Model to fetch the required data is as follows: In the data model of AdventureWorksDW the fact table FactInternetSales has the transactions where in we find the sales amount incurred in each order transaction.
The visualization will contain the bar chart to showcase the sales for different categories and subcategories of the products. In this blog we create a visualization in Python over AdventureWorksDW to showcase the Sales of different Products according to their category and sub category.