-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code for "How to Retrieve Column Names from a Table in SQL" #106
base: main
Are you sure you want to change the base?
Changes from 8 commits
83d6d4d
e1ad4d3
516a78f
ba07cbd
ebfed70
8385da9
d461edf
0c54011
fc5a7e6
616e062
5fe0433
75ff603
d54e377
04cb917
00f2476
1442fe8
fa01c86
93ca542
2f4c907
0b5e3cc
38bb793
e9559d5
7343874
d05adc9
7303097
455ac97
1f5c5a4
ff06384
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SELECT id, scores, SUM(scores) | ||
OVER (ORDER BY id) AS RunningTotal | ||
FROM Exam; | ||
|
||
SELECT id, scores, (SELECT SUM(scores) | ||
FROM exam e2 WHERE e2.id <= e1.id) AS RunningTotal | ||
FROM exam e1 ORDER BY id; | ||
|
||
SELECT s1.id, s1.scores, SUM(s2.scores) AS RunningTotal | ||
FROM Exam s1 | ||
JOIN Exam s2 ON s1.id >= s2.id | ||
GROUP BY s1.id, s1.scores ORDER BY s1.id; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
SELECT id, scores, SUM(scores) | ||
OVER (ORDER BY id) AS RunningTotal | ||
FROM Exam; | ||
|
||
SELECT id, scores, (SELECT SUM(scores) | ||
FROM exam e2 WHERE e2.id <= e1.id) AS RunningTotal | ||
jzheaux marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FROM Exam e1 ORDER BY id; | ||
|
||
SELECT s1.id, s1.scores, SUM(s2.scores) AS RunningTotal | ||
FROM Exam s1 | ||
JOIN Exam s2 ON s1.id >= s2.id | ||
GROUP BY s1.id, s1.scores ORDER BY s1.id; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
SHOW COLUMNS FROM Course; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed for this tutorial, can you remove it from the PR, please? |
||
|
||
DESCRIBE Course; | ||
|
||
SELECT COLUMN_NAME | ||
FROM INFORMATION_SCHEMA.COLUMNS | ||
WHERE TABLE_NAME = 'Course'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SELECT column_name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed for this tutorial, can you remove it from the PR, please? |
||
FROM information_schema.columns | ||
WHERE table_name = 'Course'; | ||
|
||
\d Course |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT COLUMN_NAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is needed for this tutorial, can you remove it from the PR, please? |
||
FROM INFORMATION_SCHEMA.COLUMNS | ||
WHERE TABLE_NAME = 'Course' | ||
ORDER BY ORDINAL_POSITION; | ||
|
||
SELECT c.name AS ColumnName | ||
FROM sys.columns c INNER JOIN sys.tables t | ||
ON c.object_id = t.object_id | ||
WHERE t.name = 'Course' | ||
ORDER BY c.column_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is not needed anymore