w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Adding rows automatically based on previous rows
In case you're using SQL Server, the only solution that comes to my mind is to UNION the results of two SELECT statements, one in which you select the occupancy of the classes, and one in which you calculate the non-occupancy and union the results. SELECT TOP (100) PERCENT Room, Subject, COUNT(Subject) AS Expr1 FROM dbo.Timetable GROUP BY Room, Subject UNION ALL SELECT TOP (100) PERCENT Room, 'Not Used', 60 - COUNT(Subject) AS Expr1 FROM dbo.Timetable GROUP BY Room ORDER BY t.Room Here is a SQLFiddle with the query

Categories : SQL

How to select every year from a particular year to the current year as different rows?
The easiest thing for you to do would be to create a numbers table that you would use for these types of queries. You could also use a recursive Common Table Expression to generate the list of years: ;with cte (yr) as ( select 2000 union all select yr + 1 from cte where yr+1 <=2013 ) select yr from cte; See SQL Fiddle with Demo

Categories : Sql Server

How to pause and start adding rows to data grid view on button press in C#
Let's emulate the hardware: public class Hardware { System.Timers.Timer _timer; public event EventHandler Send; public Hardware() { _timer = new System.Timers.Timer(); _timer.Interval = 1000; _timer.Elapsed += _timer_Elapsed; _timer.Start(); } void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Send(this, new SendArgs(DateTime.Now.Ticks)); } public class SendArgs : EventArgs { public long Id { get; private set; } public SendArgs(long id) { Id = id; } } } In your main form, you may add a collection object which will temporarily hold the values: public partial class Form1 : Form { List<object> _queue = new List<object>();

Categories : C#

MySQL: Convert year-by-year rows to columns?
...I see a technique for getting this done now, but I don't yet get why my technique failed. Any insight there?... You have to use an aggregate function (SUM(), MIN(), MAX() depending on your needs) and GROUP BY Try SELECT personid, SUM(CASE WHEN yearID = 1999 THEN event1 ELSE 0 END) event1_1999, SUM(CASE WHEN yearID = 2000 THEN event1 ELSE 0 END) event1_2000, SUM(CASE WHEN yearID = 2001 THEN event1 ELSE 0 END) event1_2001 FROM Table1 GROUP BY personid Same thing but with IF SELECT personid, SUM(IF(yearID = 1999, event1, 0)) event1_1999, SUM(IF(yearID = 2000, event1, 0)) event1_2000, SUM(IF(yearID = 2001, event1, 0)) event1_2001 FROM Table1 GROUP BY personid Output in both cases | PERSONID | EVENT1_1999 | EVENT1_2000 | EVENT1_20

Categories : Mysql

adding inline rows without javascript not adding rows
I think you need to update formsets factory to have more forms something like: disease = get_object_or_404(Disease, pk=disease_id) if request.method == "POST": if 'add' in request.POST: cp = request.POST.copy() total = int(cp['form-TOTAL_FORMS']) #add max_num and extra params to formset factory IndicatorFormSet2 = inlineformset_factory(Disease, Indicator, max_num=total+1, extra=1) indicatorInlineFormSet = IndicatorFormSet2(request.POST, cp, prefix='form') return HttpResponseRedirect(reverse('drui', kwargs={'disease_id':disease_id}))

Categories : Django

Select rows in one table, adding column where MAX(Date) of rows in other, related table
If we assume that tasks only become more complete, you can do this with a left outer join and aggregation: select t.ID, t.Name, coalesce(max(n.complete), 0) from tasks t left outer join notes n on t.id = n.id_task group by t.id, t.name If tasks can become "less complete" then you want the one with the last date. For this, you can use row_number(): select t.ID, t.Name, coalesce(n.complete, 0) from tasks t left outer join (select n.*, row_number() over (partition by id_task order by date desc) as seqnum from notes n ) n on t.id = n.id_task and n.seqnum = 1; In this case, you don't need a group by, because the seqnum = 1 performs the same role.

Categories : SQL

how to sum the column and get the rows based on month and year
with month_cte(userid,Current_Month) as (select userid,sum(Points)Current_Month from tbl_points where datepart(mm,PointsDate)=datepart(mm,getdate()) and datepart(YY,PointsDate)=datepart(yy,getdate()) group by userid) , year_cte(userid,Current_year) as (select userid,sum(Points)Current_Year from tbl_points where datepart(YY,PointsDate)=datepart(yy,getdate()) group by userid) select Distinct t.Userid, Current_Month, Current_Year From tbl_points T left join month_cte mc on T.userid=mc.userid left join year_cte yc on t.userid=yc.userid

Categories : Asp Net

Using Matlab, how can I group rows by year into a structure?
It's not loop free, but close enough I guess. for ii = 1:length(yrsStr)-1 struct(ii).data = X(X(:,1) >= yrsStr(ii) & X(:,1) < yrsStr(ii+1),:); end struct(length(yrsStr)).data = X(X(:,1) >= yrsStr(length(yrsStr)),:); I can't think of a faster way of doing the last line. (Except using if, or adding a term in the end of yrsStr with a big number, and make the loop go an extra step. The last one would be: yrsStr(end+1) = inf; for ii = 1:length(yrsStr)-1 struct(ii).data = X(X(:,1) >= yrsStr(ii) & X(:,1) < yrsStr(ii+1),:); end Good luck!

Categories : Matlab

PL/SQL to fetch sample rows for each month in a year
Perhaps something like this: select doc_id , date from ( select doc_id , date , row_number() over (partition by trunc(date, 'MM') order by dbms_randon.value ) as rn from your_table ) where rn <= 200 order by date, doc_id ; The analytic ROW_NUMBER() function produces a number for each record grouped by month (achieved by truncating the date with the 'MM' mask). Ordering by DBMS_RANDOM will randomise the sort order. Remember to initialise DBMS_RANDOM before running the query to get a truly random sort order. Find out more.

Categories : Oracle

Deleting Multiple Rows in a Matrix
Instead of deleting them after, just don't load them to start with. You can also short cut re-reading the file twice, as it appears you have a column limit of 9 set, so for each row, just pad it out with 0's to that size.... eg: import csv from itertools import chain, islice, repeat COLS = 9 # or pre-scan file to get max columns FILL_VALUE = 0 # or None, or blank for instance with open(filename) as fin: csvin = csv.reader(fin) # use appropriate delimiter/dialect settings non_blanks = (row for row in csvin if row[0]) # filter out rows with blank 1st col matrix = [list(islice(chain(row, repeat(FILL_VALUE)), COLS)) for row in non_blanks] Depending what you're doing with the data, you may also wish to look at the numpy module and the available loadtxt() method.

Categories : Python

faster and efficient way of deleting rows
Auto filter is fast - definitely the way to go - but it hides data rows and doesn't delete them. Since your code turns the filter off at the end, the hidden rows come back. Instead, you should apply the filter, select all, copy, paste into new sheet, and delete the old sheet. This will be very fast - and do exactly what you are asking for. Apologies that I am not posting working code - typing on ipad...

Categories : Excel

List of deleting rows in datagridview
Use dataGridView1.SelectedRows to get a collection (DataGridViewRowCollection type) that contains all the rows selected. Same works for columns (dataGridView1.SelectedColumns) and cells (dataGridView1.SelectedCells). http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedrows.aspx

Categories : C#

Deleting rows with specific rules
I just tried the following codes on my desktop and it seems to do the trick. I made a as the cell array you had. L = size(a, 1); mask = false(L, 1); for ii = 1:L if isnumeric(a{ii, 1}) && (a{ii, 1} == 137 || a{ii, 1} == 2) mask(ii) = true; elseif ~isempty(a{ii, 3}) && strcmp(a{ii, 3}(end-1:end), ':T') mask(ii) = true; end end b = a(~mask, :) Now, b should be the cell array you wanted. Basically, I created a logical mask that indicates the position of rows that satisfy the rules, then use the inverse of it to call out the rows.

Categories : Matlab

deleting multiple rows via checkbox
PHP is automatically converting your checkboxes' POST value to an array, due to the fact that you are using array notation in the name attribute. Try something like this: $ids = implode( ',', $id ); $stmt = $mydb->prepare("update messages SET deleted ='yes' where to_user = ? and id IN(?) "); $stmt->bind_param('ss', $user, $ids); It's not clear from your code where $user is coming from.

Categories : PHP

Deleting Rows in VBA if it satisfies some criteria
Try this. Sub DeleteRows() Dim flag As Range, exitFlags As Range Set exitFlags = Selection //NOTE: just select the ExitFlags column For Each flag In exitFlags If flag = 1 Then flag.EntireRow.Delete Shift:=xlUp End If Next End Sub

Categories : Excel

Deleting certain rows from a data frame
It sounds like you actually want to split your dataframe, not delete rows from it. If the dataframes are of equal sizes and you want the three extracted dataframes to be random samples, specify something like: split(df, sample(1:3,dim(df)[1],TRUE)) to get a list of the three sampled, mutually exclusive dataframes. No need to delete anything from the original dataframe. Also, if you want to have the dataframes have different sizes, you can specify a prob argument in sample.

Categories : R

Changing a cell in a row of a DataGrid(WPF) is changing cells in rows below
Try using this: <DataGrid Name="SimpleDataGrid" ScrollViewer.CanContentScroll="False" ... /> for scrolls in terms of physical units. It DataGrid CanContentScroll it is enabled by default. For more information see MSDN.

Categories : C#

Deleting multiple rows from database by checkboxes
Javascript Since you are using jquery there is better way :) <script type="text/javascript"> var is_activate = true; // we will track which input button was clicked :) jQuery(function($) { $("#form input#check_all").change(function() { var inputs = $("#form input[type='checkbox']"); if ( $(this).is(":checked") ) { inputs.prop( "checked", true ); // inputs.attr( "checked", true ); // if its not working } else { inputs.removeAttr( "checked" ); } }); // Track clicked button $("#form input[type=submit]").on("click",function(e) { is_activate = ( $(this).hasClass("activate_btn") ) ? true : false; }); $("#form").submit(function(e) { e.preventDefault(); var string = ( is_activate ) ? 'ac

Categories : PHP

Deleting multiple rows based on row number(s)
This expression does not do what you think it does: WHERE RN IN (@RowNum) It is looking for cases where @RowNum is '1,2'. And this causes the problem, because '1,2' cannot be converted to an integer. You have declared the parameter an integer when you define the procedure, but then call it with a string. You can do what you want with: WHERE ','+@RowNum+',' like '%,'+RN+',%' The extra commas ensure that "1" doesn't match "10". EDIT: There are essentially three approaches (that I can think of) for handling a string of comma delimited integers as real integers (which is better because the query will use integers). One is to use the split() function, which returns a table of the elements of a delimited string. You can google for various implementations of it. The second is to us

Categories : C#

Issue when deleting rows from my database using html, php, js
I don't think this will work $sql="DELETE FROM BCD WHERE id='$Categorie', '$SerieNummer', '$MacAdress', '$ProductCode', '$Prijs', '$RekNummer','$PaletNummer' ,'$Hoeveelheid', '$Aantekeningen'"; You should separate the parameters with AND or OR, depending on what your successful delete criteria needs not a comma, also provide the column name each time. Something like $sql="DELETE FROM BCD WHERE id='$Categorie' AND serial_number='$SerieNummer', //etc It would be better to delete based on a primary key rather than such a range of values Also do not use mysql_ functions, use mysqli or PDO with parameterised queries

Categories : PHP

Deleting dynamically created table rows
you are binding event when row clicked $('#newbook input[type="button"]').click(function () { $(this).closest('tr').remove(); }); this should at the end of your code and remove the binding event with element.onclick

Categories : Javascript

Error deleting rows in entity framework
By the call of context.xticketitem.Select(p => p.TicketID == ticketID); you will get a list of booleans that do not exist in context. I think you should do something like this: var ticketitem = context.xticketitem.Where(p => p.TicketID == ticketID); ticketItem.ToList().ForEach(r => context.xticketitem.DeleteObject(r)); context.SaveChanges(); EDIT: I've moved .ToList() on the next line to make differences between our snippets more evident. Let's try revise it step by step: When you call var ticketitem = context.xticketitem.Select(p => p.TicketID == ticketID); You are creating query that will go by all xticketitems and return whether each item's TicketID equals ticketID variable passed as an argument to your Delete method. Result of this query is IEnumerable<bool>.

Categories : Entity Framework

COUNT(*) takes long even after deleting all rows
After DELETE FROM Sdata try using OPTIMIZE TABLE Sdata to really discard the unused rows, or in the future, use TRUNCATE Sdata which will do this automatically for you. Quote from here: In MyISAM tables, deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions. To reclaim unused space and reduce file sizes, use the OPTIMIZE TABLE statement or the myisamchk utility to reorganize tables.

Categories : Mysql

Issue with Deleting rows from my second Table in my page
You shouldn't mix the delete's because you might have an instance when one id be the same as the other, so you'll delete the wrong thing. But I don't believe that is your primary problem: Your select is SELECT ID2, Klant, Categorie1, SerieNummer1, MacAdress1, ProductCode1, Prijs1, Hoeveelheid1, Aantekeningen1 FROM CDE But your delete is: DELETE FROM CDE WHERE id = ?"; You're delete should probably be: DELETE FROM CDE WHERE ID2 = ?"; To Prevent Deleting the wrong thing: The easiest thing to do here, is change you're delete user JavaScript to accept an action parameter and specify which delete you want to perform, because both delete attempts are running right now. JavaScript You don't need the JavaScript twice on the same page. Just have it one time in your HEAD or right befo

Categories : PHP

MongoDB not deleting rows, no error using c# driver
Found out what was causing this eventually! Like all good issues, this one was caused by me, as my dependency injection configuration was all set up correctly, and was pointing to the correct collection, however in the test rather than pointing to the "Entries" collection it was pointing to "Entry". It didn't click, even when I was using the GUI to check the table values, and the queries being sent seemed fine. Anyway there is no issues around searching using GUIDs etc, it was a red herring, so at least the problem is now solved, I hope this helps anyone else who is being an idiot like myself :)

Categories : C#

R: Conditional deleting rows and columns in a matrix
Here is a vectorized approach: i <- as.vector(row(m)) j <- as.vector(col(m)) k <- matrix(m == m[cbind(i, i)] & m < m[cbind(j, j)], nrow(m)) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] # [1,] FALSE TRUE TRUE TRUE FALSE FALSE FALSE # [2,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE # [3,] FALSE FALSE FALSE TRUE FALSE FALSE FALSE # [4,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE # [5,] FALSE TRUE FALSE FALSE FALSE FALSE FALSE # [6,] FALSE FALSE TRUE TRUE FALSE FALSE FALSE # [7,] FALSE TRUE FALSE FALSE FALSE FALSE FALSE delete.idx <- sort(unique(i[k])) # [1] 1 3 5 6 7 keep.idx <- setdiff(seq_len(nrow(m)), delete.idx) # [1] 2 4 m[keep.idx, keep.idx] # [,1] [,2] # [1,] 373 204 # [2,] 204 239

Categories : R

SQLDF Left Join still deleting rows from Table A
Can you try the following sql query? SELECT TimeSeries.StartYear, TimeSeries.StartMonthNo, CommonName, EstimatedBiomassg, ScaledProportionofDominantNektonBiomass FROM TimeSeries LEFT JOIN TrawlBiomassbyMonth ON TimeSeries.StartYear = TrawlBiomassbyMonth.StartYear AND TimeSeries.StartMonthNo = TrawlBiomassbyMonth.StartMonthNo WHERE CommonName = 'White shrimp' AND RegionCode = 1") From reading your post, the issue is there are some NULL fields in the right hand table, and you wish to include all rows from the left hand table even when there is no match? Could you possibly setup a http://sqlfiddle.com/ ? PS due to my stackoverflow rep I was unable to comment, so although this isnt an answer, I'm trying to help

Categories : SQL

Deleting Rows meeting certain criteria in excel using vba (autofilter)
Each AutoFilter statement overrides the previous one, so in the end, your code only deletes all rows with Sick Accrued in column B -- try adding the delete statement between each Autofilter: With rngTable .AutoFilter Field:=ColumntoFilter1, Criteria1:=FilterCriteria1 .Offset(1, 0).EntireRow.Delete .AutoFilter Field:=ColumntoFilter2, Criteria1:=FilterCriteria2 .Offset(1, 0).EntireRow.Delete .AutoFilter Field:=ColumntoFilter3, Criteria1:=FilterCriteria3 .Offset(1, 0).EntireRow.Delete .AutoFilter Field:=ColumntoFilter4, Criteria1:=FilterCriteria4 .Offset(1, 0).EntireRow.Delete .AutoFilter Field:=ColumntoFilter5, Criteria1:=FilterCriteria5 .Offset(1, 0).EntireRow.Delete .AutoFilter Field:=ColumntoFilter6, Criteria1:=FilterCriteria6 .Offset(1, 0).EntireRow.Delete .AutoFilter Field:=ColumntoFi

Categories : Vba

Innodb memcached plugin in RDS not deleting expired rows
I'm by no means an expert, as I've just started to play around with memcached myself. However, this is from the MySQL documentation for the python tutorial. It seems to be saying that if you use the InnoDB memcached plugin, MySQL will handle cache expiration, and it really doesn't matter what you enter for the cache expire time. And for the flags, expire, and CAS values, we specify corresponding columns based on the settings from the sample table demo.test. These values are typically not significant in applications using the InnoDB memcached plugin, because MySQL keeps the data synchronized and there is no need to worry about data expiring or being stale.

Categories : Mysql

When inserting and deleting rows in a tableView, how do I prevent it trying to add them at invalid locations?
Well, if there will only be two cells you don't need to make this overly complex. What I would do is use heightForRowAtIndexPath: and begin/end updates to do the heavy lifting for me. First, set up your each of your cells to display the username/password label/textfield/whatever you want on their top half, and the "details" on the bottom half. Then just modify heightForRowAtIndexPath: to by default return a value that will only expose the top half of the cell and only conditionally be large enough to reveal the entire cell. From there all you have to do is a little indexPath comparison and you're golden. - (void)viewDidLoad { [super viewDidLoad]; self.currentIndexPath = [NSIndexPath indexPathForRow:NSIntegerMax inSection:0]; } - (CGFloat)tableView:(UITableView *)tableView he

Categories : IOS

Deleting rows and columns in matrix based on values in diagonal in R
Use the diag function and logical comparison with < and the [ subset operator like this... idx <- ! diag(m) < 5 m <- m[ idx , idx ] e.g. m # x1 x2 x3 x4 #x1 13 15 12 25 #x2 23 4 23 34 #x3 21 11 1 11 #x4 11 22 23 33 idx <- ! diag(m) < 5 m <- m[ idx , idx ] m # x1 x4 #x1 13 25 #x4 11 33

Categories : R

Locating specific values within cells and deleting identified rows
Sub Remove_Expendables() Dim c as range, rngDel as range set c= activesheet.cells(rows.count, "AA").end(xlup) Application.ScreenUpdating = FALSE Do While c.row > 1 If c.value like "L-*" Then if rngDel is nothing then set rngDel=c else set rngDel=application.union(rngDel,c) end if end if set c=c.offset(-1,0) Loop if not rngDel is nothing then rngDel.entirerow.delete Application.ScreenUpdating = TRUE End Sub

Categories : String

CakePHP: How to make auto-increment values contiguous again after deleting rows
You can drop the MySQL column manually, then re-add it with the same properties. The rows will be reordered. Alternatively, use these commands: SET @count = 0; UPDATE `users` SET `users`.`id` = @count:= @count + 1; Replace users and id appropriately. You can reset your auto incrementing id column also with: ALTER TABLE `users` AUTO_INCREMENT = 1; Where users is replaced with the name of your table.

Categories : PHP

OpenXML Spreadsheet deleting rows causes excel unreadable content errors
Based on the XML of the worksheet, this part: <x:row r="1" spans="1:37"> <x:c r="A1" t="s"> <x:v /> </x:c> </x:row> should not exist outside of the SheetData element. In fact, there appears to be a duplicate, since <x:row> <x:c r="A1" t="inlineStr"> <x:is> <x:t>TestResultFileId</x:t> </x:is> </x:c> </x:row> also exist. Note that the "actual" header Row has no RowIndex assigned, but according to the CellReference of "A1", this particular row is on row 1. Note that this: var rows = sheetData.Elements<Row>().Where(r => r.RowIndex > 1).ToArray(); will probably ignore any Row objects without the RowIndex assigned (I didn't test this though...).

Categories : C#

I want to make certain rows delete automatically based on age
Something like the code below should do the trick. In this example I am starting from row two and checking a date in column F to see if this is greater than the defined interval days old (21 here), you can change the initialisation of these variables as you require: Sub delete_old() Dim rowDate Dim curDate Dim interval Dim curAdd Dim vCell As Range ' set interval to an appropriate no of days interval = 21 ' can be more precise e.g. for 5 mins: (1 / 24) / 12 curDate = Now() ' assuming we want to start from row 2 and that date is in column F Set vCell = Range("F2") ' Set Do loop to stop when an empty cell is reached. Do Until IsEmpty(vCell) curAdd = vCell.Address If curDate - vCell.Value >= interval Then vCel

Categories : Excel

Creating layout that automatically takes several rows when shrinked
Use the FlowLayout: http://qt-project.org/doc/qt-5.0/qtwidgets/graphicsview-flowlayout.html TotalCommander was not made however with QT but with Delphi and (FreePascal lately).

Categories : Qt

How to let a datagridview automatically generate new rows to fill the empty space
You can do something like this: private void Form1_Resize(object sender, EventArgs e) { dataGridView1.Rows.Clear(); while ((dataGridView1.Rows.Count == 0) || (dataGridView1.Rows[0].Height * dataGridView1.Rows.Count < (dataGridView1.Height - dataGridView1.ColumnHeadersHeight))) { dataGridView1.Rows.Add(/*Your generated row information*/); } } Hope it helps. Felipe Campos São Paulo - Brazil

Categories : C#

ListView Odd/Even Rows Refresh Automatically When Scrolling Down Or Selecting AnotherItem
The item changes back to the default background because the view gets recycled. This is the same problems of checkboxes losing their checked state Check out this answer too see how to handle it: CheckBox gets unchecked on scroll in a custom listview As for your second problem, I believe it's already answered here: highlighting the selected item in the listview in android Hope it helps

Categories : Android

Compare start and end dates across multiple rows
SQL Fiddle select * from subscription s0 where not exists ( select 1 from subscription s1 where s0.contact_id = s1.contact_id and s1.start_date = s0.end_date ) order by contact_id, id

Categories : SQL

how to get start and end rows for null recods in Table in SQL
You didn't specify a DBMS so this is an ANSI SQL solution: select min(datetime) as start_date, max(datetime) as end_date, max(datetime) - min(datetime) as days from ( select datetime, v1, v2, sum(case when v1 is null and v2 is null then null else 1 end) over (order by datetime) as group_flag from foo ) t group by group_flag order by 1 SQLFiddle example: http://sqlfiddle.com/#!12/12fdb/1

Categories : SQL



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.