2
To explain, I prefer an example:
I want to find out which item is the most sold along with the salty chicken.
For this, I tried the following approach and failed miserably by lack of technical knowledge:
-Fetch all coupons (sales) containing the code of the chicken salty [OK]
-Pick up all items from these coupons [OK]
-Add the individual quantity of each item that is sold. The highest value is the result.
I tried using SQL only.
The relevant structure of the tables is as follows:
Table product
codbarra | Description
Table sale
idvenda | dtvenda
Table vdaitem
idvdaitem | vdaitem | codbarra | Qtde | dtvenda
I’m not sure the table structure is correct. There seems to be a column missing from the vdaitem table to link to the sales table
– bruno
@Jeffersonlucas: Your approach is correct and can be implemented in a modular way in T-SQL, through the use of CTE (common table Expression).
– José Diz
Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).
– Sorack