| | |
Return the sum of elements in a row
Please support our Database Design advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Is there is query with which I can get the sum of elements in one row?
I am trying to develop an atttendance application. Design as follows-
<date1> <date2> <date3> <date4>--- <attended>
<rollno1> 1 0 1 1 3
<rollno2> 0 0 1 1 2
<rollno3> 0 1 0 0 1
I am trying to get the attended field.
Is it possible, or is it a bad design?
Please suggest an alternate design if so.
I am absolutely new to database design.
I am trying to develop an atttendance application. Design as follows-
<date1> <date2> <date3> <date4>--- <attended>
<rollno1> 1 0 1 1 3
<rollno2> 0 0 1 1 2
<rollno3> 0 1 0 0 1
I am trying to get the attended field.
Is it possible, or is it a bad design?
Please suggest an alternate design if so.
I am absolutely new to database design.
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 42
•
•
•
•
Design as follows-
<date1> <date2> <date3> <date4>--- <attended>
<rollno1> 1 0 1 1 3
<rollno2> 0 0 1 1 2
<rollno3> 0 1 0 0 1
Simple rule: if you are forced to expand the number of columns when new data need to be recorded, you must put this sort of data into rows, and not in columns! So a rather better design is:
table: roda roll# dates ------------------- rollno1 date1 rollno1 date3 rollno1 date4 rollno2 date3 rollno2 date4 rollno3 date2
For example: select attended:
select roll#, count(roll#) as attended from roda group by roll#
will give:
roll# attended ----------------- rollno1 3 rollno2 2 rollno3 1
Further advice: Tables always must have (yes, they must have that!) primary key, for example primary key(roll#, dates).
Hope this will help you.
krs,
tesu
![]() |
Similar Threads
- Addition with Two Dimensional Arrays (C++)
- calculating values using onclick (JavaScript / DHTML / AJAX)
- Problem with loops (C++)
- Two-Dimensional Arrays (Assembly)
- Magic Square (Java)
- Please I Need U Again (C++)
- a problem wilth C program (C)
Other Threads in the Database Design Forum
- Previous Thread: preSolved problem, I need a link
- Next Thread: Nationality Lookup table
| Thread Tools | Search this Thread |
Tag cloud for Database Design





