SQL Calculation

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/9

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

10 Terms

1
New cards

Calculations

  • use basic SQL structure:

    • SELECT column (s) and/or calculations

    • FROM table

    • WHERE conditions and/or calculations

    • ORDER BY column(s) and/or calculations;

  • add calculations in this SQL structure

    • write a formula to do calculations & columns are used as variables: column1 + column2

    • treat the formula as a column

    • any match operator can be used (+-*/)

    • complex calculations require functions like cos()

2
New cards

Audit and Data Analytic Mindset

  • think about the business, problems and issues we need to identify and address, what data we need, and what existing data can tell us

  • related questions to ask:

    • how is this related to accounting? there are no numbers here. what can we “crunch”?

    • relatedly, what kind of data analysis can we do?

    • from an auditing standpoint, how do we audit the company’s HR practice?

    • is there anything unusual in the data table?

3
New cards

Audit Question Example

  • are there any underage employees at the time of their hiring (assuming legal age for formal employment is 18)?

  • why is this the case?

    • relevant for internal auditing bc it raises questions such as: how was the company doing in terms of regulatory compliance, were they complying with external laws and regulations?

4
New cards

Calculation for Age of Employee

  • /365 would transform the answers from days to years

  • years is more relevant when determining one’s age

  • new formula is: (HireDate - BirthDate)/365

  • remember to use parenthesis ()

  • use math operators depending on the specific question we want to answer (+-*/)

<ul><li><p>/365 would transform the answers from days to years</p></li><li><p>years is more relevant when determining one’s age</p></li><li><p>new formula is: (HireDate - BirthDate)/365</p></li><li><p>remember to use parenthesis ()</p></li><li><p>use math operators depending on the specific question we want to answer (+-*/)</p></li></ul><p></p>
5
New cards

ROUND (n, p)

  • used to eliminate decimals

  • an additional step of calculation

    • n: number to round

    • p: precision (number of decimals)

  • example: SELECT LastName, FirstName, ROUND(HireDate - BirthDate)/365, 0)

    • n: the number we want to round which is (HireDate - BirthDate/365)

    • p: how many decimal places we want to keep, which in this case is 0

  • commas are needed in the formula

<ul><li><p>used to eliminate decimals</p></li><li><p>an additional step of calculation</p><ul><li><p>n: number to round</p></li><li><p>p: precision (number of decimals)</p></li></ul></li><li><p>example: SELECT LastName, FirstName, ROUND(HireDate - BirthDate)/365, 0)</p><ul><li><p>n: the number we want to round which is (HireDate - BirthDate/365)</p></li><li><p>p: how many decimal places we want to keep, which in this case is 0</p></li></ul></li><li><p>commas are needed in the formula </p></li></ul><p></p>
6
New cards

Sort Result

  • by doing so, we can tell who is the youngest or oldest at the time of hiring

  • first, add a new block ORDER BY here

    • calculations can be used with this block

  • ASC is used to present the youngest employee based on age first

<ul><li><p>by doing so, we can tell who is the youngest or oldest at the time of hiring</p></li><li><p>first, add a new block ORDER BY here</p><ul><li><p>calculations can be used with this block</p></li></ul></li><li><p>ASC is used to present the youngest employee based on age first</p></li></ul><p></p>
7
New cards

New Column Name

  • example: SELECT ROUND ((HireDate - BirthDate)/365, 0)) AS HireAge

  • use AS to change column name

<ul><li><p>example: SELECT ROUND ((HireDate - BirthDate)/365, 0)) AS HireAge</p></li><li><p>use AS to change column name</p></li></ul><p></p>
8
New cards

Filtering: Workers who are under 18 at HireDate

  • WHERE (HireDate - BirthDate)/365 <18

  • <18 would only show employees under the age of 18

  • if the result is an empty table, then there are no employees that fit this condition

  • Record 1-1 would be shown at the bottom which indicates a new, blank row in Access

  • if there are two employees with no age information, we need to use the audit mindset to include these suspicious employees in our data analysis

<ul><li><p>WHERE (HireDate - BirthDate)/365 &lt;18</p></li><li><p>&lt;18 would only show employees under the age of 18</p></li><li><p>if the result is an empty table, then there are no employees that fit this condition </p></li><li><p>Record 1-1 would be shown at the bottom which indicates a new, blank row in Access</p></li><li><p>if there are two employees with no age information, we need to use the audit mindset to include these suspicious employees in our data analysis </p></li></ul><p></p>
9
New cards

What to do if employee information is missing and how to include the employee(s)

  • example: WHERE (HireDate - BirthDate)/365 <18 OR (HireDate - BirthDate)/365 IS NULL)

  • IS NULL keyword is added and represented in the new condition bc IS NULL checks whether the new column (e.g., calculation) does not have any data and is empty or missing.

    • NULL = missing or empty value

    • NULL is not the same as a white space or a zero

  • OR will be included since the new condition with IS NULL keyword will be considered if the first condition is not satisfied (either condition)

  • it is wrong to use AND in this case

<ul><li><p>example: WHERE (HireDate - BirthDate)/365 &lt;18 OR (HireDate - BirthDate)/365 IS NULL)</p></li><li><p>IS NULL keyword is added and represented in the new condition bc IS NULL checks whether the new column (e.g., calculation) does not have any data and is empty or missing. </p><ul><li><p>NULL = missing or empty value</p></li><li><p>NULL is not the same as a white space or a zero</p></li></ul></li><li><p>OR will be included since the new condition with IS NULL keyword will be considered if the first condition is not satisfied (either condition)</p></li><li><p>it is wrong to use AND in this case</p></li></ul><p></p>
10
New cards

Steps to Answer Business Questions

  • maintain an audit and data analytics mindset

    • how to use data for auditing/business decision making

    • what data can we use and how to get data

  • know what questions to ask

    • understand the business and know existing business problems/issues

    • understand audit objectives from the auditing standpoint

  • answer the questions step by step

    • make tiny improvements at a time

  • pay attention to missing data

    • missing data is problematic

    • determine whether missing data is legitimate

    • to do so, understand the nature of the business, processes of how people do things (business process integration) and how info systems work (information control & risk and control)

  • follow up investigation

    • needed usually to understand the whole picture of the issue

Explore top flashcards

Nisäkkäät
Updated 773d ago
flashcards Flashcards (47)
31-35
Updated 79d ago
flashcards Flashcards (69)
BIOL 375 Exam 2
Updated 1026d ago
flashcards Flashcards (76)
MB3
Updated 191d ago
flashcards Flashcards (37)
Tema 6: Contexto 2
Updated 970d ago
flashcards Flashcards (30)
Emotions and moods
Updated 187d ago
flashcards Flashcards (114)
Nisäkkäät
Updated 773d ago
flashcards Flashcards (47)
31-35
Updated 79d ago
flashcards Flashcards (69)
BIOL 375 Exam 2
Updated 1026d ago
flashcards Flashcards (76)
MB3
Updated 191d ago
flashcards Flashcards (37)
Tema 6: Contexto 2
Updated 970d ago
flashcards Flashcards (30)
Emotions and moods
Updated 187d ago
flashcards Flashcards (114)