Skip to content
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

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
83d6d4d
Create sql-column-name-mysql.sql
degr8sid-code Jul 23, 2024
e1ad4d3
Create sql-column-name-sqlserver.sql
degr8sid-code Jul 23, 2024
516a78f
Update sql-column-name-mysql.sql
degr8sid-code Jul 23, 2024
ba07cbd
Create sql-column-name-postgresqlSELECT column_name FROM information_…
degr8sid-code Jul 23, 2024
ebfed70
Create running-total
degr8sid-code Sep 1, 2024
8385da9
Create running-total
degr8sid-code Sep 6, 2024
d461edf
Update and rename running-total to running-total.sql
degr8sid-code Sep 17, 2024
0c54011
Merge pull request #2 from degr8sid-code/degr8sid-code-patch-1
degr8sid-code Sep 17, 2024
fc5a7e6
Delete sql-queries/calculate-running-total directory
degr8sid-code Oct 4, 2024
616e062
Create running-total.sql
degr8sid-code Oct 4, 2024
5fe0433
Update running-total.sql
degr8sid-code Oct 4, 2024
75ff603
Delete sql-queries/sql-column-name/sql-column-name-mysql.sql
degr8sid-code Oct 4, 2024
d54e377
Delete sql-queries/running-total directory
degr8sid-code Oct 5, 2024
04cb917
Delete sql-queries/sql-column-name directory
degr8sid-code Oct 5, 2024
00f2476
Update running-total.sql
degr8sid-code Oct 5, 2024
1442fe8
Merge pull request #3 from degr8sid-code/degr8sid-code-final-running-…
degr8sid-code Oct 5, 2024
fa01c86
Create rolling-average-mssql.sql
degr8sid-code Oct 29, 2024
93ca542
Create rolling-average-mysql.sql
degr8sid-code Oct 29, 2024
2f4c907
Create rolling-average-postgresql.sql
degr8sid-code Oct 29, 2024
0b5e3cc
Create rolling-average.sql
degr8sid-code Oct 29, 2024
38bb793
Merge branch 'Baeldung:main' into main
degr8sid-code Nov 11, 2024
e9559d5
Create rolling-average-mysql.sql
degr8sid-code Nov 12, 2024
7343874
Create rolling-average-mssql
degr8sid-code Nov 12, 2024
d05adc9
Update rolling-average-mysql.sql
degr8sid-code Nov 12, 2024
7303097
Rename rolling-average-mssql to rolling-average-mssql.sql
degr8sid-code Nov 12, 2024
455ac97
Create rolling-average-postgre.sql
degr8sid-code Nov 12, 2024
1f5c5a4
Create rolling-average.sql
degr8sid-code Nov 12, 2024
ff06384
Delete sql-queries/rolling-average directory
degr8sid-code Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sql-queries/calculate-running-total/running-total.sql
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;
12 changes: 12 additions & 0 deletions sql-queries/running-total/running-total.sql
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,5 @@
SELECT column_name
Copy link

Choose a reason for hiding this comment

The 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
10 changes: 10 additions & 0 deletions sql-queries/sql-column-name/sql-column-name-sqlserver.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT COLUMN_NAME
Copy link

Choose a reason for hiding this comment

The 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;