久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我需要根據其他記錄中的其他值計算數據庫中記

I need to calculate values for a record in a database based off of other values in other records(我需要根據其他記錄中的其他值計算數據庫中記錄的值)
本文介紹了我需要根據其他記錄中的其他值計算數據庫中記錄的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要根據其他記錄中的其他值計算數據庫中記錄的值.使用 SqlServer 2012,最好的方法是什么?我正在考慮在服務器上運行的某種類型的腳本,它可以查詢它需要計算的值,計算它們并將它們插入到它需要的記錄中.我知道您可以基于 SqlServer 中的其他列計算列,但是基于不同記錄中不同列的新記錄呢?

I need to calculate values for a record in a database based off of other values in other records. Using SqlServer 2012, what would be the best way to do this? I'm thinking some type of script that runs on the server that may be able to query for the values it needs to compute, compute them, and insert them into the record it needs to. I know you can have computed columns based off of other columns in SqlServer, but what about new records based off of different columns in different records?

謝謝!

我在 MVC4 Razor 網站上使用谷歌圖表表格來顯示特定用戶按月和年購買的商品;看起來像這樣:

I'm using a google charts table on an MVC4 Razor website to show items purchased by specific users by month and year; looks something like this:

電子郵件地址 |購買價值 |年 |月

Email Address | Purchase Value | Year | Month

這目前工作得很好.我查詢數據庫中按用戶和按月和年分組的購買,并對購買求和,然后將值放入表中.我也有只顯示一個月和一年的類別過濾器,所以一次只顯示一個用戶.

This currently works absolutely fine. I query the database for purchases by user and group by month and year and sum the purchases, and I put the values in the table. I also have category filters that only show one month and one year, so only one user is shown at a time.

現在管理層想要在類別過濾器上選擇全部",這意味著對于每年的每個月和每年的總計,我將不得不計算每個用戶的累積購買價值并將其放入桌子;您可以想象,如果用戶列表變得很長,這可能需要一些時間.因此,我認為最好的選擇可能是擁有一個腳本,按年份和用戶分組購買,并在該年度內的任何時間每次捐贈時更新新記錄;顯然,你會為一年中的每個月做同樣的事情.這樣,當用戶請求頁面時,我不必擔心計算這個.我只是不確定如何為 SQLServer 編寫一個能夠執行此類操作的腳本.

Now management wants an 'All' selection on the category filter, which means that for every month of every year, and every year total, I'm going to have to compute a cumulative purchase value for each user and put it in the table; you can imagine, if the users list gets very long, this could take some time. So, I think the best option would probably be to have a script that groups purchases by year and by user and updates a new record every time a donation is made anytime within that year; obviously, you'd do the same for each month of the year. That way, I wouldn't have to worry about computing this when the user requests the page. I'm just not sure how to go about writing a script for SQLServer that would be able to do something like this.

推薦答案

這顯示了如何根據其他記錄中的其他值計算數據庫中記錄的值.該示例是用 TSQL 編寫的,可以在 SQL Server 上執行.您將需要更改腳本以使用您的表和列.

This shows how to calculate values for a record in a database based off of other values in other records. The example is written in TSQL and can be executed on SQL Server. You will need to change the script to use your tables and columns.

DECLARE @total dec(12,2), @num int --Variable declaration

SET @total = (SELECT SUM(Salary) FROM Employee) --Capture sum of employee salaries

SET @num = (SELECT COUNT(ID) FROM Employee) --Capture the number of employees

SELECT @total 'Total', --calculate values for a record in a database based off of other values in other records
        @num 'Number of employees',
        @total/@num 'Average'
INTO
    dbo.AverageSalary

希望這會有所幫助.

這篇關于我需要根據其他記錄中的其他值計算數據庫中記錄的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 男女啪啪免费视频 | 欧美成人a | 国产精品第一 | 国产日韩一区二区三区 | 国产精品一区二区在线免费观看 | 少妇特黄a一区二区三区 | 亚洲视频在线看 | 天天久久 | 伊人av在线 | 国产精品网站在线观看 | 国产精品成人免费视频 | 亚洲综合激情网 | 噜噜噜在线 | 免费观看av | 亚洲欧美日韩综合 | 国产又粗又大又爽 | 中文一级片 | 中文字幕第一区综合 | 国产精品久久久国产盗摄 | 成人精品国产 | 国产日韩欧美一区二区 | 久在线 | 色视频www在线播放国产人成 | 老司机深夜福利视频 | 日本大尺度吃奶做爰久久久绯色 | 一区二区欧美日韩 | 一区二区三区四区在线播放 | 黄色三级视频在线观看 | 一区二区三区免费 | 国产资源在线观看 | 精品国产一二三区 | 久久视频免费看 | 亚洲精品在线视频 | 一区二区国产精品 | 国产精品久久久久久久久 | 成人在线视频网 | av超碰在线 | 国产精品久久一区二区三区 | 亚洲天堂视频在线观看 | 成人午夜网站 | 特级毛片爽www免费版 |