So I am posting this after seraching alot of SO queries and answers.
I have a table that gives the booktime, pickup time. I want to calculate the average timedifference between the two timestamps group on hourly basis and area-wise.The desired output is given below
This all needs to be done in SQL
<table>
<tr>
<td>Hour</td>
<td>Order#</td>
<td>AverageResponseTime</td>
</tr>
<tr>
<td>1</td>
<td>20</td>
<td>15:13</td>
</tr>
<tr>
<td>2</td>
<td>10</td>
<td>02:45</td>
</tr>
<tr>
<td>3</td>
<td>120</td>
<td>01:20</td>
</tr>
<tr>
<td>24</td>
<td>10</td>
<td>19:05</td>
</tr>
</table>
Try this-
select
AreaName,
datepart(hour, BookTime) as BookTimeHour,
(AVG(Datediff(second, booktime, pickuptime))/60.0) as AvgTimeInMinutes
from #MyTable
group by
AreaName,
datepart(hour,BookTime);
Related
HTML:
<div class="attach">
<app-table>
<table class="table"> //
<thead>
<tr>
<th><span>Name</span></th>
<th><span>Address</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>aaa</td>
<td>bbb</td>
</tr>
<tr>
<td>aaa111</td>
<td>bbb222</td>
</tr>
</tr>
</tbody>
</table>
</app-table>
</div>
The page may have multiple web tables. However, parent element "attach" is unique for this table.
How can I count the total number of rows and columns? I found lot of info online but I could not fix it.
from www.tutorialspoint.com/how-to-count-the-number-of-rows-in-a-table-in-selenium-with-python:
# identifying the number of rows having <tr> tag
rows = driver.find_elements_by_xpath("//table/tbody/tr")
# len method is used to get the size of that list
print(len(rows))
#to close the browser
driver.close()
Number of cells may vary per row. But you can use xpath to count those too:
row1 = driver.find_elements_by_xpath("//table/tbody/tr")
cols = row1.find_elements_by_xpath("//td")
print(len(cols))
You have include the class name in the xpath to make it unique in your case.
#Number of columns in the table
cols = driver.find_elements_by_xpath("//div[#class="attach"]//table/thead//th")
print(cols)
#Number of rows in the table
rows = driver.find_elements_by_xpath("//div[#class="attach"]//table/tbody//tr")
print(rows )
We can resolve this in Java Language as follows:
List rows=driver.findElements(By.xpath("//div[#class="attach"]//tbody//tr"));
int rowCount=rows.size();
List columns=driver.findElements(By.xpath("//div[#class="attach"]//table//th"));
int columnCount=columns.size();
Is there a way to transpose a table which is filled using Vue?
The html now is:
<table>
<tr>
<th>Date</th>
<th>Temp(max)</th>
<th>Temp(min)</th>
<th>Rain</th>
<th>Icon</th>
</tr>
<tr v-for="forecast in forecasts">
<td>{{forecast.date}}</td>
<td>{{forecast.maxTemp}}°C</td>
<td>{{forecast.minTemp}}°C</td>
<td>{{forecast.rain}} mm</td>
<td><i :class="translateIcon(forecast.icon)"></i></td>
</tr>
</table>
But I want to change this table view to have the dates in Row 1, the max temp in Row 2, etc.
I have a table with a few columns. I want to get data from two of the columns; email and URL.
One column being email. I want distinct emails.
The second column is a url. I want to get only the urls that match what I'm looking for, for example, xyz.
So the table looks like this:
<table>
<tbody>
<tr>
<td>Email</td>
<td>URL</td>
</tr>
<tr>
<td>user#yahoo.com</td>
<td>xyz</td>
</tr>
<tr>
<td>user#gmail.com</td>
<td>abc</td>
</tr>
<tr>
<td>user#outlook.com</td>
<td>xyz</td>
</tr>
<tr>
<td>user#email.com</td>
<td>xyz</td>
</tr>
</tbody>
</table>
How do I execute a query so that only the emails from the xyz url are found?
Unless I’m missing something, you just need to do:
Select Distinct Email
From YourTable
Where URL = 'xyz'
I have 2 sections in a database. Drafts and Albums. So we get a draft for an album. The drafts have requirements, and later an album is created. That album also has requirements, but the requirements on both sides are entered independently. Some will change, be dropped, new ones added, etc. I am trying to make a query to compare those requirements, when an album is assigned as having coming from a specific draft.
The table structure looks like this:
Drafts:ID, draft fields
Draft Requirements: ID, Draft FK, Requirement Type FK
Albums: ID, Drafk FK (not required immediately, but will only be able to audit against a draft, if this is not null), album fields
Album Requirements: ID, Album FK, Requirement Type FK
So I want to create a query with the following:
Draft Fields, Album Fields, Draft Requirements, Album Requirements
Basically if there are 10 requirements it would look like this (excuse the code, wanted to try to make a table, so you can really see):
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg .tg-yw4l{vertical-align:top}
</style>
<table class="tg">
<tr>
<th class="tg-yw4l">Draft Req</th>
<th class="tg-yw4l">Album Req</th>
</tr>
<tr>
<td class="tg-yw4l">R1</td>
<td class="tg-yw4l">R1</td>
</tr>
<tr>
<td class="tg-yw4l">R2</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l">R3</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l">R4</td>
</tr>
<tr>
<td class="tg-yw4l">R5</td>
<td class="tg-yw4l">R5</td>
</tr>
<tr>
<td class="tg-yw4l">R7</td>
<td class="tg-yw4l"></td>
</tr>
<tr>
<td class="tg-yw4l"></td>
<td class="tg-yw4l">R8</td>
</tr>
<tr>
<td class="tg-yw4l">R9</td>
<td class="tg-yw4l">R9</td>
</tr>
</table>
This is the first part of the query, with just basic info for the draft and album:
SELECT vw_CMP_Contacts.ContactNo, vw_CMP_Contacts.ContactName, vw_CMP_Matches.MatchNo, vw_CMP_Matches.MatchName,
tblContactDraft.txtOrganization, tblDraftStatus.txtDraftStatus, tblMAlbumStatus.txtAlbumStatus, tblAlbumType.txtAlbumType
FROM ((((vw_CMP_Matches
INNER JOIN (tblMAlbums INNER JOIN tblContactDraft ON tblMAlbums.FKContactDraft = tblContactDraft.ID) ON vw_CMP_Matches.CM_MID = tblMAlbums.FKMatch)
INNER JOIN tblDraftStatus ON tblContactDraft.FKDraftStatus = tblDraftStatus.ID)
INNER JOIN tblMAlbumStatus ON tblMAlbums.FKMAlbumStatus = tblMAlbumStatus.ID)
INNER JOIN tblAlbumType ON tblMAlbums.FKAlbumType = tblAlbumType.ID)
INNER JOIN vw_CMP_Contacts ON vw_CMP_Matches.ContactNo = vw_CMP_Contacts.ContactNo
Next I have to join the draft requirements, by draft fk, to tbldraftreqs, and req type by fk req type. I have the same for albums in an tblalbumreqs.
when i try to join those, I get no results, even though both have requirements. The issue is, i'm directly joining drafts to albums, but then I need both requirements, and for them to line up together or alone, depending on if they both have the same requirement.
Make sense?
I'd love any pointers in solving this conundrum!
I figured it out. There is only so much I can explain about a question. If the only comments are to complain that I didn't explain enough, I'll just keep researching on my own.
Anyway, I hope this helps someone else trying to do the same kind of joining.
SELECT mc.ID as mcid, mc.FKContactDraft as Draftid, rq.ID, rq.txtRequirementType, Draft.FKRequirementType AS DraftReq, cont.FKRequirementType AS MCReq
from tblMAlbums mc
full join tblReqType rq on 1=1
left join tblContactDraftRequirements Draft on mc.FKContactDraft = Draft.FKContactDraft and rq.ID = Draft.FKRequirementType
left join tblMAlbumRequirements cont on mc.ID = cont.FKMC and rq.ID = cont.FKRequirementType
where mc.FKContactDraft is not null
I'm trying to list records for a locations view of recently created at or updated records from the last 24 hours using activerecord but am a beginner developer needing some help.
Does anyone know a solution for implementing this in the controller/view? Thanks in advance for the help.
Since you're using Rails, I will assume that you have these files, corresponding to a Locations resource:
app/views/locations/index.html.erb
app/controllers/locations_controller.rb
app/models/location.rb
There are a few ActiveRecord alternatives for querying records in the past 24 hours:
This example demonstrates the concept that you can specify a range for querying the timestamp columns.
#locations = Location.where(updated_at: (Time.now - 24.hours)..Time.now)
As pointed out in the comments below, there may be a fraction of a second precision error with the above query. You can store a variable, now = Time.now, to ensure that your query spans exactly 24 hours.
now = Time.now
#locations = Location.where(updated_at: (now - 24.hours)..now)
You could eliminate the subtraction operation and let Rails handle it for you, which may also result in a slight offset from an exact window of 24 hours.
#locations = Location.where(updated_at: 24.hours.ago..Time.now)
You can also forego the hash syntax in the where parameters, passing a SQL string that filters with the > comparison operator.
#locations = Location.where('updated_at > ?', 24.hours.ago)
In your controller, add an index action, with your preferred query approach:
def index
#locations = Location.where(updated_at: 24.hours.ago..Time.now)
end
In your view, add these lines:
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Created_At</th>
<th>Updated_At</th>
</tr>
</thead>
<tbody>
<% #locations.each do |location| %>
<tr>
<td><%= location.id %></td>
<td><%= location.name %></td>
<td><%= location.created_at %></td>
<td><%= location.updated_at %></td>
</tr>
<% end %>
</tbody>
</table>