SQL questions, please summarize the existing data according to the following requirements, thank you

Updated on Car 2024-04-05
3 answers
  1. Anonymous users2024-02-07

    Basically not achievable. If you want to get the results of Table 2, you can only change the structure of Table 1 to make it meet the requirements of categorizing and summarizing by one field.

    According to the results (Table 2), it can be seen that there is only one categorical field (and only one to get such a simple and clear result). However, in Table 1, the data you need to classify are stored in 7 fields, and if you classify multiple fields according to Table 1, Table 2 will not be obtained.

    If possible, change the structure of Table 1 or use the query statement to reconstruct a new table of the data to be summarized, and then classify and summarize Table 2.

  2. Anonymous users2024-02-06

    select Name List. Article number, article name list. Goods name, goods name list.

    Units, name lists. Specifications, last schedule. Quantity, last period.

    Amount, purchase table. The number of incoming goods, the incoming list. Purchase money, purchase list.

    Tracking number, shipping table. Number of shipments, shipping table. Shipment money, shipping table.

    Tracking number, (Formula 1) as Balance Quantity, (Formula 2) as Balance Amount.

    Gold from the Cargo Name List left outer join

    Last Schedule on Cargo Name List. Catalog Number = Previous Schedule. Catalog number left outer join

    Incoming Goods Table on Incoming Goods Table. Catalog Number = Incoming Table. Catalog number left outer join

    Shipping table on Shipping table. Catalog Number = Shipping Table. Catalog number left outer join

    That's all I can do for you. Let's try this left outer join.

    Because the logic you expressed is not very clear, and there is no cost to reflect, there is really no way to write you specific, just an idea.

    In addition, you can write these tables in the view in this way, isn't it ready to use?

    Hope it helps!

  3. Anonymous users2024-02-05

    You don't think clearly, I'm halfway through writing and find out that your logic is not right :

    1.There is a description of the previous period, each period has to be carried forward once, where is your carryover mark, is it a date or a status mark? If you don't have this, how do you know which ones are in the current period and which ones are in the previous period?

    2.You want to find the goods information of the specified date (range) of the specified manifest, if there is a tracking number, the purchase quantity and the shipment volume are not summarized in one row, and you cannot ask for the tracking number if you want to summarize it to one line.

    3.You also have to specify the date (range) can not have the previous period, if you want to the last period, you can not check from the shipping table and the purchase table of the two schedules, you should build a separate flow table, in this table will be the order number, date, article number, purchase (sales, inventory) quantity amount, as well as the amount of purchase (sales, storage) before the transaction into this table.

    You want to be logical and clear, I can give you a stored procedure, I don't know if you understand it or not.

Related questions
5 answers2024-04-05

F get domain contrast is a formatting function (should be written by yourself), the first parameter (arg prod spec id) according to the second parameter (120) formatting and return the result to the v bill code, according to the function naming method, the above ** should be the standard format for getting the date.

5 answers2024-04-05

With a view or an index.

create index >>>More

4 answers2024-04-05

dateadd(dd, datediff(dd,0,getdate())0) means to return the current date. >>>More

13 answers2024-04-05

Convert nvarchar to decimal and then float, e.g

declare @vnum varchar(20) >>>More

8 answers2024-04-05

I don't really understand the server and the like, but a 32-bit machine can't read 8G memory, and the effective memory is at most 4G, unless it's a 64-bit machine.