Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
This is my practice question. I removed the images and added the table into HTML code format.
This below code is of Un Normalized formed.
<table>
<thead>
<tr>
<th>ENo </th>
<th>BNo </th>
<th>Branch </th>
<th>Name </th>
<th>Designation </th>
<th>Salary </th>
<th>DeptNo </th>
<th>DeptName </th>
<th>FromDate </th>
<th>ToDate </th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>Deer Road</td>
<td>John</td>
<td>Manager</td>
<td>30000</td>
<td>1</td>
<td>HR</td>
<td>05-04-2001</td>
<td>31-12-2006</td>
</tr>
<tr>
<td>1</td>
<td>2</td>
<td>Deer Road</td>
<td>John</td>
<td>Manager</td>
<td>30000</td>
<td>2</td>
<td>Finance</td>
<td>01-01-2007</td>
<td>--</td>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td>Argyll street</td>
<td>Ann</td>
<td>Assistant</td>
<td>8000</td>
<td>1</td>
<td>HR</td>
<td>01-09-2005</td>
<td>--</td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td>Main Road</td>
<td>David</td>
<td>Supervisor</td>
<td>15000</td>
<td>3</td>
<td>IT</td>
<td>01-07-2002</td>
<td>--</td>
</tr>
</tbody>
</table>
I converted UNF to 1NF by simply adding another Employee ID (EId) column because currently columns are not uniquely identifying.
This below code is of 1NF Form:
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-cly1{text-align:left;vertical-align:middle}
.tg .tg-9qwi{background-color:#fd6864;border-color:inherit;font-weight:bold;text-align:center;vertical-align:middle}
.tg .tg-yla0{font-weight:bold;text-align:left;vertical-align:middle}
.tg .tg-vwbk{background-color:#fd6864;text-align:left;vertical-align:bottom}
<table class="tg">
<thead>
<tr>
<th class="tg-9qwi">Eid</th>
<th class="tg-yla0">ENo </th>
<th class="tg-yla0">BNo </th>
<th class="tg-yla0">Branch </th>
<th class="tg-yla0">Name </th>
<th class="tg-yla0">Designation </th>
<th class="tg-yla0">Salary </th>
<th class="tg-yla0">DeptNo </th>
<th class="tg-yla0">DeptName </th>
<th class="tg-yla0">FromDate </th>
<th class="tg-yla0">ToDate </th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-vwbk">1</td>
<td class="tg-cly1">1</td>
<td class="tg-cly1">2</td>
<td class="tg-cly1">Deer Road</td>
<td class="tg-cly1">John</td>
<td class="tg-cly1">Manager</td>
<td class="tg-cly1">30,000</td>
<td class="tg-cly1">1</td>
<td class="tg-cly1">HR</td>
<td class="tg-cly1">05-04-2001</td>
<td class="tg-cly1">31-12-2006</td>
</tr>
<tr>
<td class="tg-vwbk">1</td>
<td class="tg-cly1">1</td>
<td class="tg-cly1">2</td>
<td class="tg-cly1">Deer Road</td>
<td class="tg-cly1">John</td>
<td class="tg-cly1">Manager</td>
<td class="tg-cly1">30,000</td>
<td class="tg-cly1">2</td>
<td class="tg-cly1">Finance</td>
<td class="tg-cly1">01-01-2007</td>
<td class="tg-cly1">--</td>
</tr>
<tr>
<td class="tg-vwbk">2</td>
<td class="tg-cly1">1</td>
<td class="tg-cly1">3</td>
<td class="tg-cly1">Argyll street</td>
<td class="tg-cly1">Ann</td>
<td class="tg-cly1">Assistant</td>
<td class="tg-cly1">8,000</td>
<td class="tg-cly1">1</td>
<td class="tg-cly1">HR</td>
<td class="tg-cly1">01-09-2005</td>
<td class="tg-cly1">--</td>
</tr>
<tr>
<td class="tg-vwbk">3</td>
<td class="tg-cly1">2</td>
<td class="tg-cly1">1</td>
<td class="tg-cly1">Main Road</td>
<td class="tg-cly1">David</td>
<td class="tg-cly1">Supervisor</td>
<td class="tg-cly1">15,000</td>
<td class="tg-cly1">3</td>
<td class="tg-cly1">IT</td>
<td class="tg-cly1">01-07-2002</td>
<td class="tg-cly1">--</td>
</tr>
</tbody>
</table>
I converted from 1NF to 2NF by breaking the table into three subtables.
this is 2NF subtables code:
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-9ger{background-color:#fcff2f;text-align:left;vertical-align:bottom}
.tg .tg-ctz4{background-color:#3166ff;text-align:left;vertical-align:bottom}
.tg .tg-u24d{background-color:#fcff2f;text-align:left;vertical-align:middle}
.tg .tg-za14{border-color:inherit;text-align:left;vertical-align:bottom}
.tg .tg-7zrl{text-align:left;vertical-align:bottom}
.tg .tg-yla0{font-weight:bold;text-align:left;vertical-align:middle}
.tg .tg-16v0{background-color:#fcff2f;font-weight:bold;text-align:left;vertical-align:bottom}
.tg .tg-exyj{background-color:#34ff34;font-weight:bold;text-align:left;vertical-align:bottom}
.tg .tg-4aos{background-color:#34ff34;text-align:left;vertical-align:bottom}
.tg .tg-xtan{background-color:#3166ff;font-weight:bold;text-align:left;vertical-align:bottom}
.tg .tg-gl5e{background-color:#fcff2f;font-weight:bold;text-align:left;vertical-align:middle}
</style>
<table class="tg">
<thead>
<tr>
<th class="tg-za14"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-yla0">2NF</th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
<th class="tg-7zrl"></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-9ger"></td>
<td class="tg-9ger"></td>
<td class="tg-16v0">Employee Table</td>
<td class="tg-9ger"></td>
<td class="tg-u24d"></td>
<td class="tg-7zrl"></td>
<td class="tg-7zrl"></td>
<td class="tg-exyj">Branch Table</td>
<td class="tg-4aos"></td>
<td class="tg-7zrl"></td>
<td class="tg-xtan" colspan="2">Department Table</td>
</tr>
<tr>
<td class="tg-9ger"></td>
<td class="tg-9ger"></td>
<td class="tg-9ger"></td>
<td class="tg-9ger"></td>
<td class="tg-u24d"></td>
<td class="tg-7zrl"></td>
<td class="tg-7zrl"></td>
<td class="tg-4aos"></td>
<td class="tg-4aos"></td>
<td class="tg-7zrl"></td>
<td class="tg-ctz4"></td>
<td class="tg-ctz4"></td>
</tr>
<tr>
<td class="tg-16v0">EId</td>
<td class="tg-16v0">ENo</td>
<td class="tg-16v0">Name</td>
<td class="tg-gl5e">Designation</td>
<td class="tg-gl5e">Salary</td>
<td class="tg-7zrl"></td>
<td class="tg-7zrl"></td>
<td class="tg-exyj">BNo</td>
<td class="tg-exyj">Branch</td>
<td class="tg-7zrl"></td>
<td class="tg-xtan">DeptNo</td>
<td class="tg-xtan">DeptName</td>
</tr>
<tr>
<td class="tg-9ger">1</td>
<td class="tg-9ger">1</td>
<td class="tg-9ger">John</td>
<td class="tg-u24d">Manager</td>
<td class="tg-9ger">30,000</td>
<td class="tg-7zrl"></td>
<td class="tg-7zrl"></td>
<td class="tg-4aos">1</td>
<td class="tg-4aos">Main Road</td>
<td class="tg-7zrl"></td>
<td class="tg-ctz4">1</td>
<td class="tg-ctz4">HR</td>
</tr>
<tr>
<td class="tg-9ger">2</td>
<td class="tg-9ger">1</td>
<td class="tg-9ger">Ann</td>
<td class="tg-9ger">Assistant</td>
<td class="tg-9ger">8,000</td>
<td class="tg-7zrl"></td>
<td class="tg-7zrl"></td>
<td class="tg-4aos">2</td>
<td class="tg-4aos">Deer Road</td>
<td class="tg-7zrl"></td>
<td class="tg-ctz4">2</td>
<td class="tg-ctz4">Finance</td>
</tr>
<tr>
<td class="tg-9ger">3</td>
<td class="tg-9ger">2</td>
<td class="tg-9ger">David</td>
<td class="tg-9ger">Supervisor</td>
<td class="tg-9ger">15,000</td>
<td class="tg-7zrl"></td>
<td class="tg-7zrl"></td>
<td class="tg-4aos">3</td>
<td class="tg-4aos">Argyll Street</td>
<td class="tg-7zrl"></td>
<td class="tg-ctz4">3</td>
<td class="tg-ctz4">IT</td>
</tr>
</tbody>
</table>
after that, I stuck on how to normalized this from the date and to date column.
I need suggestions with which table I have to add this from and to date column?
Normalization never introduces new attributes. You introduced Eid.
This is a practice question, not a real-world database design. For example, employees don't have last names in this design. That's not "real world". But it's a defensible simplification for a practice question.
In the context of a practice question, "Eno" suggests that column should be understood as "Employee number". We'd usually consider "Employee number" in a table like this to be unique, but John and Ann have the same Eno. That raised a red flag for you, and that's a good thing. But in this context, I would have questioned the data first (ask your professor), because that looks like a typo to me. In the context of this practice question, you should consider "Name" to be identifying.
Normalization doesn't proceed by "breaking a table into subtables". Simplifying a little, normalization proceeds by decomposing a table into projections of that table, based on functional dependencies.
You don't have enough information to know what to do with the attributes FromDate and ToDate, because you don't know what those column names mean. That suggests that "FromDate" and "ToDate" are bad names for these columns. Use more descriptive names, so people don't have to guess.
"FromDate" and "ToDate" might have to do with
Designation (John was a manager from FromDate until ToDate),
Branch (John was assigned to Branch from FromDate until Todate),
Department (John was assigned to Department from FromDate until Todate),
Salary (John drew Salary from FromDate until ToDate),
and so on.
This is one place functional dependencies show they're essential.
I want to find the average of the grouped values
with the rule (if time(n+1) - time(n) < 40 minutes) and by feature
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
overflow:hidden;padding:10px 5px;word-break:normal;}
.tg th{border-color:black;border-style:solid;border-width:1px;font-family:Arial, sans-serif;font-size:14px;
font-weight:normal;overflow:hidden;padding:10px 5px;word-break:normal;}
.tg .tg-0pky{border-color:inherit;text-align:left;vertical-align:top}
</style>
<table class="tg">
<thead>
<tr>
<th class="tg-0pky">feature</th>
<th class="tg-0pky">value</th>
<th class="tg-0pky">time</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,76</td>
<td class="tg-0pky">20200508 11:13:06</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,69</td>
<td class="tg-0pky">20200508 11:13:13</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,94</td>
<td class="tg-0pky">20200508 11:13:20</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,73</td>
<td class="tg-0pky">20200508 11:13:27</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,79</td>
<td class="tg-0pky">20200508 12:16:55</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,76</td>
<td class="tg-0pky">20200508 12:17:03</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">60,1</td>
<td class="tg-0pky">20200508 12:17:10</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">59,95</td>
<td class="tg-0pky">20200508 12:17:18</td>
</tr>
<tr>
<td class="tg-0pky">Diameter</td>
<td class="tg-0pky">60,02</td>
<td class="tg-0pky">20200508 12:17:36</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,1</td>
<td class="tg-0pky">20200508 05:23:30</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,08</td>
<td class="tg-0pky">20200508 05:23:35</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,04</td>
<td class="tg-0pky">20200508 05:23:40</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,06</td>
<td class="tg-0pky">20200508 05:23:46</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,16</td>
<td class="tg-0pky">20200508 05:23:52</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,69</td>
<td class="tg-0pky">20200508 06:03:05</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,65</td>
<td class="tg-0pky">20200508 06:03:13</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,64</td>
<td class="tg-0pky">20200508 06:03:18</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,39</td>
<td class="tg-0pky">20200508 06:03:24</td>
</tr>
<tr>
<td class="tg-0pky">Weight</td>
<td class="tg-0pky">9,44</td>
<td class="tg-0pky">20200508 06:03:29</td>
</tr>
</tbody>
</table>
I have tried to do something like this:
I tried something like:
SELECT avg(ISNULL(Value,0)), feature FROM V_Value GROUP BY (SELECT avg(Value) from V_Value t1, V_Value t2 where DATEDIFF(minute,t1.DateMis+t1.HourMis,t2.DateMis+t2.HourMis) <= '40' ) order by feature
but it don't work. returns an error on the group by clause
groupings should be:
because every 40 minutes he groups the values of the same feature
the result should be:
Diameter | 59,78
Diameter | 59,924
Weight | 9,088
Weight | 9,562
I took a while to solve this but after some googling and trying stuff I reached this solution.
It rounds the datime down to the desired precision (in this case 40min), and used this rounded time as a grouping column.
SELECT
[rounded_time]
,[feature]
,AVG([value]) AS [value]
FROM (
SELECT
[time]
,DATEADD(mi, DATEDIFF(mi, 0, [time])/40*40, 0) as [rounded_time]
,[feature]
,[value]
FROM V_Value
) as x
To explain what it does you can see the following code sample, it will explain it better than word
DECLARE #SampleData TABLE
(TimeCol Datetime
)
INSERT INTO #SampleData VALUES
('2020-06-04 17:00:00'),('2020-06-04 17:05:00'),('2020-06-04 17:10:00')
,('2020-06-04 17:15:00'),('2020-06-04 17:20:00'),('2020-06-04 17:25:00')
,('2020-06-04 17:30:00'),('2020-06-04 17:35:00'),('2020-06-04 17:40:00')
,('2020-06-04 17:45:00'),('2020-06-04 17:50:00'),('2020-06-04 17:55:00')
,('2020-06-04 18:00:00'),('2020-06-04 18:05:00'),('2020-06-04 18:10:00')
,('2020-06-04 18:15:00'),('2020-06-04 18:20:00'),('2020-06-04 18:25:00')
,('2020-06-04 18:30:00'),('2020-06-04 18:35:00'),('2020-06-04 18:40:00')
SELECT
[TimeCol] AS [Source_Time]
,DATEDIFF(mi, 0, [TimeCol]) AS [MinSince1900] --minutes since 1900-01-01 00:00
,DATEDIFF(mi, 0, [TimeCol])/40*40 AS [MinSince1900_Rounded] --integer divison truncates the decimal part, therefore the result is always rounded down (in this case in blocks of 40min)
,DATEADD(mi, DATEDIFF(mi, 0, [TimeCol])/40*40, 0) AS [Rounded_Time]--add the above minutes back to 1900-01-01 00:00 and you get your grounded datetime
FROM #SampleData
I have thead and tbody in the table.
Thead contains a few s in . Each of it have an id. I need to find the index of td in thead by id and then find by index in tbody.
<table>
<thead>
<tr>
<td data-date="2019-08-05"></td>
<td data-date="2019-08-06"></td> //find index of this element
<td data-date="2019-08-07"></td>
</tr>
</thead>
<tbody>
<tr>
<td>aaa</td>
<td>bbb</td> //find this element by found index
<td>ccc</td>
</tr>
</tbody>
</table>
upd
<table>
<thead>
<tr>
<td data-date="2019-08-05"></td>
<td data-date="2019-08-06"></td>
<td data-date="2019-08-07"></td>
<td data-date="2019-08-08"></td> //find index of this element
<td data-date="2019-08-09"></td>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2"></td>
<td rowspan="2" class="rrrr">event1 2019-08-06</td>
<td class="rrrr">event1 2019-08-07</td>
<td class="rrrr"event1 2019-08-08</td> //find this element by found index
<td rowspan="2"></td>
</tr>
<tr>
<td class="rrrr">event2 2019-08-07</td>
<td class="rrrr">event2 2019-08-08</td> //find this element by found index
</tr>
</tbody>
</table>
This xpath expression
//tbody//td[count(//thead//td[#data-date='2019-08-06']/preceding-sibling::*)+1]
selects
<td>bbb</td>
Below is the table which i am rendering which is working fine in IE
and
Firefox. But not working as expected in chrome.
12th header(certificate of Incorporation or equivaleent) is coming at first and second header(RequestType) is coming at 12th place and 1st header(Request#) is coming at 2nd place
place.
When i removed all the and trying to show one by one. It was working
fine till (data-title="'Bank'"). and when i just added another
(data-title="'Borad'"). Header is coming improperly.
<table ng-show="reqTrackCtrl.data.length" ng-table="reqTrackCtrl.reqTrackingTable">
<tbody>
<tr ng-repeat="item in reqTrackCtrl.data">
<td data-title="'Request#'" sortable="'id'" class="item-id">{{item.id}}</td>
<td data-title="'Request Type'" sortable="'class'">{{item.class}}</td>
<td data-title="'Status'" sortable="'requestStatus'">{{item.request}}
<td data-title="'Requester'" sortable="'requestedBy'">{{item.requestedBy}}</td>
<td data-title="'Requested Date'" sortable="'requestedDate'">{{item.requestedDate}}</td>
<td data-title="'Assigned To'" sortable="'assignedTo'">{{item.assignedTo}}</td>
<td data-title="'Completion Date'" sortable="'completionDate'">{{item.completionDate}}</td>
<td ng-if="formType != 'DU'" data-title="'Business Unit'" sortable="'Unit'">{{item.Unit}}</td>
<td ng-if="formType != 'DU'" data-title="'Legal Entity Name'" sortable="'EntityName'">{{item.EntityName}}</td>
<td ng-if="formType != 'DU'" data-title="'Bank'">{{item.bank}}</td>
<td data-title="'Board'">{{item.boardResolution}}</td>
<td data-title="'Certificate of Incorporation or Equivalent'">{{item.certificate Of incorporation}}</td>
<td data-title="'Bylaws'"><div >{{item.bylaws}}</div></td>
<td data-title="'Incumbency'">{{item.incumbency}}</td>
<td ng-show="formType != 'ABC'" data-title="'Delegation'">{{item.delegation}}</td>
<td ng-show="formType != 'ABC'" data-title="'FAT'">{{item.FAT}}</td>
<td data-title="'Bank Forms'">{{item.bankForms}}</td>
<td data-title="'Signature'">{{item.signature}}</td>
<td data-title="'Bank System'">{{item.bankSystem}}</td></td>
<td data-title="'Kyriba'">{{item.kyriba}}</td>
<td data-title="'Account'">{{item.account}}</td>
<td data-title="'Shared'">{{item.shared}}</td>
</tr>
</tbody>
</table>
For resolving this issue I have updated ng-table version, from 0.5.4 to 1.0.0.
I have this XML string and would like to parse and traverse it
<table>
<tbody>
<tr>
<th colspan="1">Issue ID</th>
<th>Role</th>
<th>Abstract</th>
<th>Status</th>
<th colspan="1">Assigned To</th>
<th>Estimate</th>
<th colspan="1">Start Date</th>
<th colspan="1">End Date</th>
<th colspan="1">Actual</th>
<th colspan="1">Milestones</th>
</tr>
<tr>
<td class="highlight-blue" data-highlight-colour="blue">265884</td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue">Task 1</td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
<td class="highlight-blue" data-highlight-colour="blue"> </td>
</tr>
<tr>
<td> </td>
<td>QA</td>
<td>Verify fix</td>
<td>In-Progress</td>
<td>Karl</td>
<td>1</td>
<td>Feb 11</td>
<td> </td>
<td>0.25</td>
<td>
<ul>
<li>Feb 11: Change Code Review to "No Review Required"</li>
<li>Feb 11: Requested SB for testing</li>
<li>Feb 13: Still waiting for SB</li>
<li>Feb 18: (need to follow up) -> Done Re-requested SB copy</li>
</ul>
</td>
</tr>
</tbody>
</table>
I would like to get the number of <tr>'s as well as do for-loop in the array to access each column. I looked into XmlReader but not quite sure how to use it without using a GridPanel.
Perhaps Ext.data.Store alone can achieve that, but I'm still not quite familiar with it and can't find any suitable methods here: http://extjs.cachefly.net/ext-3.3.1/docs/?class=Ext.data.XmlReader
Maybe you can use Ext selector (http://docs.sencha.com/extjs/3.4.0/#!/api/Ext-method-select).
Sample code for your case: https://fiddle.sencha.com/#fiddle/4pv