tsql

Calculate the general average grade with sum group by

ⅰ亾dé卋堺 提交于 2020-12-26 11:12:56
问题 I have to display for each user the first and last name, year as studyYear, age, average grade, and also the general average grade. General average grade I need to be computed like this: Sum(AverageGrade)/ total number of grades [userID] [FirstName] [LastName] [BirthDate] [Year] [AverageGrade] My problem is the sum of the the general average grade. I understand that I have to use Sum(AverageGrade) + group by but it wont work, help? select FirstName+' '+LastName as FullName, AverageGrade ,Year

Calculate the general average grade with sum group by

十年热恋 提交于 2020-12-26 11:11:51
问题 I have to display for each user the first and last name, year as studyYear, age, average grade, and also the general average grade. General average grade I need to be computed like this: Sum(AverageGrade)/ total number of grades [userID] [FirstName] [LastName] [BirthDate] [Year] [AverageGrade] My problem is the sum of the the general average grade. I understand that I have to use Sum(AverageGrade) + group by but it wont work, help? select FirstName+' '+LastName as FullName, AverageGrade ,Year

Calculate the general average grade with sum group by

久未见 提交于 2020-12-26 11:11:36
问题 I have to display for each user the first and last name, year as studyYear, age, average grade, and also the general average grade. General average grade I need to be computed like this: Sum(AverageGrade)/ total number of grades [userID] [FirstName] [LastName] [BirthDate] [Year] [AverageGrade] My problem is the sum of the the general average grade. I understand that I have to use Sum(AverageGrade) + group by but it wont work, help? select FirstName+' '+LastName as FullName, AverageGrade ,Year

Select top rows until value in specific column has appeared twice

我的梦境 提交于 2020-12-23 17:08:07
问题 I have the following query where I am trying to select all records, ordered by date, until the second time EmailApproved = 1 is found. The second record where EmailApproved = 1 should not be selected. declare @Test table (id int, EmailApproved bit, Created datetime) insert into @Test (id, EmailApproved, Created) values (1,0,'2011-03-07 03:58:58.423') , (2,0,'2011-02-21 04:55:52.103') , (3,0,'2011-01-29 13:24:02.103') , (4,1,'2010-10-12 14:41:54.217') , (5,0,'2010-10-12 14:34:15.903') , (6,0,

SQL(SQL/Oracle) insert value from a select statement using sequence

守給你的承諾、 提交于 2020-12-15 05:09:33
问题 I want to insert (user_id) value from a select statement like below without identity column. Currently this query doesn't follow the sequence number in order. Kindly advise. https://dbfiddle.uk/?rdbms=oracle_18&fiddle=195728e48cc8a5a0047fec8837e9f217 回答1: This is answering the original version of the question. If you are asking can you have identical SQL statements to use a sequence in SQL Server and in Oracle then, no, you cannot. In Oracle, the syntax is: INSERT INTO b_user ( user_id /*, ..

SQL - Getting Sum of 'X' Consecutive Values where X is an Integer in another Row (With Categories)

与世无争的帅哥 提交于 2020-12-14 06:30:36
问题 Say for example, I wanted to SUM all the values from the current row until the provided count. See table below: For example: Category A, Row 1: 10+15+25 = 50 (because it adds Rows 1 to 3 due to Count) Category A, Row 2: 15+25+30+40 = 110 (because it adds Rows 2 to 5 due to count) Category A, Row 5: 40+60 = 100 (because it Adds Rows 5 and 6. Since the count is 5, but the category ends at Row 6, so instead of that, it sums all available data which is Rows 5 and 6 only, thus having a value of

SQL - Getting Sum of 'X' Consecutive Values where X is an Integer in another Row (With Categories)

陌路散爱 提交于 2020-12-14 06:28:19
问题 Say for example, I wanted to SUM all the values from the current row until the provided count. See table below: For example: Category A, Row 1: 10+15+25 = 50 (because it adds Rows 1 to 3 due to Count) Category A, Row 2: 15+25+30+40 = 110 (because it adds Rows 2 to 5 due to count) Category A, Row 5: 40+60 = 100 (because it Adds Rows 5 and 6. Since the count is 5, but the category ends at Row 6, so instead of that, it sums all available data which is Rows 5 and 6 only, thus having a value of

How to combine multiple tables with different columns

╄→尐↘猪︶ㄣ 提交于 2020-12-13 06:31:23
问题 I have 3 tables. I want the school table to set the data of major_subject and get the minor_subject on the result. And also set automatically units 3.0 for major_subject since this table has no column. I tried to use UNION but I get error since major_subject column is not the same with minor_subject table. school major_subject | school_id | school_name | | subj_name | date_offered | ----------------------------- --------------------------------- | 1 | schoolA | | Business101 | 2021/01/01 | |

How to combine multiple tables with different columns

♀尐吖头ヾ 提交于 2020-12-13 06:31:22
问题 I have 3 tables. I want the school table to set the data of major_subject and get the minor_subject on the result. And also set automatically units 3.0 for major_subject since this table has no column. I tried to use UNION but I get error since major_subject column is not the same with minor_subject table. school major_subject | school_id | school_name | | subj_name | date_offered | ----------------------------- --------------------------------- | 1 | schoolA | | Business101 | 2021/01/01 | |

SQL Server : find recent consecutive records that are greater than 5

核能气质少年 提交于 2020-12-13 04:52:27
问题 I need to write a query that shows the result broken down by FormID that have a value greater than 5 based on the most recent LogDate . Based on the most recent LogDate , if there was a value that was less than 5, it should display values from that point that are greater than 5 as the values under 5 is a 'reset' if you will. I am essentially looking at recent consecutive LogDate records that are greater than 5. Say we have the following record set: FormID Value LogDate -----------------------