Search Results

Search found 2646 results on 106 pages for 'fetch'.

Page 9/106 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • PostgreSQL - fetch the row which has the Max value for a column

    - by Joshua Berry
    I'm dealing with a Postgres table (called "lives") that contains records with columns for time_stamp, usr_id, transaction_id, and lives_remaining. I need a query that will give me the most recent lives_remaining total for each usr_id There are multiple users (distinct usr_id's) time_stamp is not a unique identifier: sometimes user events (one by row in the table) will occur with the same time_stamp. trans_id is unique only for very small time ranges: over time it repeats remaining_lives (for a given user) can both increase and decrease over time example: time_stamp|lives_remaining|usr_id|trans_id ----------------------------------------- 07:00 | 1 | 1 | 1 09:00 | 4 | 2 | 2 10:00 | 2 | 3 | 3 10:00 | 1 | 2 | 4 11:00 | 4 | 1 | 5 11:00 | 3 | 1 | 6 13:00 | 3 | 3 | 1 As I will need to access other columns of the row with the latest data for each given usr_id, I need a query that gives a result like this: time_stamp|lives_remaining|usr_id|trans_id ----------------------------------------- 11:00 | 3 | 1 | 6 10:00 | 1 | 2 | 4 13:00 | 3 | 3 | 1 As mentioned, each usr_id can gain or lose lives, and sometimes these timestamped events occur so close together that they have the same timestamp! Therefore this query won't work: SELECT b.time_stamp,b.lives_remaining,b.usr_id,b.trans_id FROM (SELECT usr_id, max(time_stamp) AS max_timestamp FROM lives GROUP BY usr_id ORDER BY usr_id) a JOIN lives b ON a.max_timestamp = b.time_stamp Instead, I need to use both time_stamp (first) and trans_id (second) to identify the correct row. I also then need to pass that information from the subquery to the main query that will provide the data for the other columns of the appropriate rows. This is the hacked up query that I've gotten to work: SELECT b.time_stamp,b.lives_remaining,b.usr_id,b.trans_id FROM (SELECT usr_id, max(time_stamp || '*' || trans_id) AS max_timestamp_transid FROM lives GROUP BY usr_id ORDER BY usr_id) a JOIN lives b ON a.max_timestamp_transid = b.time_stamp || '*' || b.trans_id ORDER BY b.usr_id Okay, so this works, but I don't like it. It requires a query within a query, a self join, and it seems to me that it could be much simpler by grabbing the row that MAX found to have the largest timestamp and trans_id. The table "lives" has tens of millions of rows to parse, so I'd like this query to be as fast and efficient as possible. I'm new to RDBM and Postgres in particular, so I know that I need to make effective use of the proper indexes. I'm a bit lost on how to optimize. I found a similar discussion here. Can I perform some type of Postgres equivalent to an Oracle analytic function? Any advice on accessing related column information used by an aggregate function (like MAX), creating indexes, and creating better queries would be much appreciated! P.S. You can use the following to create my example case: create TABLE lives (time_stamp timestamp, lives_remaining integer, usr_id integer, trans_id integer); insert into lives values ('2000-01-01 07:00', 1, 1, 1); insert into lives values ('2000-01-01 09:00', 4, 2, 2); insert into lives values ('2000-01-01 10:00', 2, 3, 3); insert into lives values ('2000-01-01 10:00', 1, 2, 4); insert into lives values ('2000-01-01 11:00', 4, 1, 5); insert into lives values ('2000-01-01 11:00', 3, 1, 6); insert into lives values ('2000-01-01 13:00', 3, 3, 1);

    Read the article

  • MySqli Prepared Statment Fetch Row

    - by pws5068
    I'm looking for an efficient way to select a specific row with a php prepared statement. $iDB = new mysqliDB(); $stmt = $iDB->prepare($sql); $stmt->bind_param('s',$searhStr); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($objID,$typeID,$year,$updated); // Now jump to row $rowNumber echo("Obj ID = {$objID}"); Any suggestions? Thanks!

    Read the article

  • How do I fetch a set of rows from data table

    - by cmrhema
    Hi, I have a dataset that has two datatables. In the first datatable I have EmpNo,EmpName and EmpAddress In the second datatable I have Empno,EmpJoindate, EmpSalary. I want a result where I should show EmpName as the label and his/her details in the gridview I populate a datalist with the first table, and have EmpNo as the datakeys. Then I populate the gridview inside the datatable which has EmpNo,EmpJoinDate and EmpAddress. My code is some what as below Datalist1.DataSource = dt; Datalist1.DataBind(); for (int i = 0; i < Datalist1.Items.Count; i++) { int EmpNo = Convert.ToInt32(Datalist1.DataKeys[i]); GridView gv = (GridView)Datalist1.FindControl("gv"); gv.DataSource = dt2; gv.DataBind(); } Now I have a problem, I have to bind the Details of the corresponding Employee to the gridview. Whereas the above code will display all the details of all employees in the gridview. If we use IEnumerable we give a condition where(a=a.eno=EmpNo), and bind that list to the gridview. How do I do this in datatable. kindly do not give me suggestions of altering the stored procedure which results the values in two tables, because that cannot be altered. I have to find a solution within the existing objects I have. Regards Hema

    Read the article

  • Fetch MP3 ID3 tag under linux

    - by exic
    Hi, I have a few mp3 files which are not tagged. Winamp has a nice feature which I think is called "autotag" and which is very good at finding out artist and title for files. I'd like something like this for unix, so that I could possibly get artists and titles for my untagged files. Do you know some program which does this? Thanks.

    Read the article

  • Fetch wrong SVN credentials with Python

    - by user1029968
    Could anyone here let me know how can I check if provided SVN credentials (username and password) are proper? With pysvn there is callback_get_login parameter but in case credentials are wrong, callback is prompted over and over without any way to cancel this and return failure information. Please let me know how can I (not neccesserily with pysvn) check if provided SVN credentials are okay. Thank you in advance!

    Read the article

  • jQuery Autocomplete fetch and parse data source with custom function, except not

    - by Ben Dauphinee
    So, I am working with the jQuery Autocomplete function, and am trying to write a custom data parser. Not sure what I am doing incorrectly, but it throws an error on trying to call the autocompleteSourceParse function, saying that req is not set. setURL("ajax/clients/ac"); function autocompleteSourceParse(req, add){ var suggestions = []; $.getJSON(getURL()+"/"+req, function(data){ $.each(data, function(i, val){ suggestions.push(val.name); }); add(suggestions); }); return(suggestions); } $("#company").autocomplete({ source: autocompleteSourceParse(req, add), minLength: 2 });

    Read the article

  • Jsonp request using jquery to fetch bing web results

    - by Blankman
    using this as a guide: http://msdn.microsoft.com/en-us/library/dd250846.aspx can someone help me with the jquery call? Do I actually pass in the javascript code for the callback, or just the name of the function? BingSearch = function($bingUrl, $bingAppID, $keyword, $callBack) { $bingUrl = $bingUrl + "?JsonType=callback&JsonCallback=" + $callBack + "&Appid=" + $bingAppID + "&query=" + encodeURI($keyword) + "&sources=web"; $.ajax({ dataType: 'jsonp', jsonp: $callBack, url: $bingUrl, success: function(data) { alert('success'); $callBack(data); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("error: " + textStatus); } }); };

    Read the article

  • count and fetch rows in php

    - by Mac Taylor
    hey guys i have a table in my mysql database named (names) now everyone can save their real names now i want to query this table and find out how many times these names used forexample the output should be : Jakob (20) Jenny (17) now this is my own code : list($usernames) =mysql_fetch_row(mysql_query('SELECT name FROM table_user GROUP BY name ORDER BY COUNT(name) DESC LIMIT 50 ')); list($c) =mysql_num_rows(mysql_query('SELECT COUNT(name) FROM table_user GROUP BY name ')); print $usernames.'('.$c.')' is this a correct approach ?!

    Read the article

  • Core Data: fetch an NSManagedObject by its properties

    - by niklassaers
    Hi guys, I have an object NetworkMember that has no attributes but is defined by its relationships Person, Network, Level and Role. In my app, I've found all the four relationships, but I want to make sure not to double-register my NetworkMember, thus I'd like to search for this NSManagedObject before instantiating it. How should I write a query that queries for an NSManagedObject just consisting of relationships? Cheers Nik

    Read the article

  • I cannot fetch appointments immediately via EWS on exchange server

    - by DappleHou
    I developed a transport agent for exchange server. In this agent, I code to invoke EWS to get appointments. I cannot get appointments immediately by the code. wait for a while, then go to get appointments again. This time, its OK. Why not immediately? Here is my code. To solve it, I have to get appointments repeatedly till find appointments. do{ webServiceData.FindItemsResults<webServiceData.Appointment> results = folder.FindAppointments(view); Thread.sleep(100); }while(results.Items.Count==0); Note that the code is inside transport agent. Is there any other solutions?

    Read the article

  • How to fetch populated associated models in CakePHP when calling read()

    - by Code Commander
    I have the following Models: class Site extends AppModel { public $name = "Site"; public $useTable = "site"; public $primaryKey = "id"; public $displayField = 'name'; public $hasMany = array('Item' => array('foreignKey' => 'siteId')); public function canView($userId, $isAdmin = false) { if($isAdmin) { return true; } return array_key_exists($this->id, $allowedSites); } } and class Item extends AppModel { public $name = "Item"; public $useTable = "item"; public $primaryKey = "id"; public $displayField = 'name'; public $belongsTo = array('Site' => array('foreignKey' => 'siteId')); public function canView($userId, $isAdmin = false) { // My problem appears to be the next line: return $this->Site->canView($userId, $isAdmin); } } In my controller I am doing something like this: $result = $this->Item->read(null, $this->request->id); // Verify permissions if(!$this->Item->canView($this->Session->read('userId'), $this->Session->read('isAdmin'))) { $this->httpCodes(403); die('Permission denied.'); } I notice that in Item->canView() $this->data['Site'] is populated with the column data from the site table. But it merely an array and not an object. On the other hand $this->Site is a Site object, but it has not been populated with the column data from the site table like $this->data. What is the proper way to have CakePHP get the associated model as the object and containing the data? Or am I going about this all wrong? Thanks!

    Read the article

  • Fetch the most viewed data in databases

    - by Erik Edgren
    I want to get the most viewed photo from the database but I don't know how I shall accomplish this. Here's my SQL at the moment: SELECT * FROM photos AS p, viewers AS v WHERE p.id = v.id_photo GROUP BY v.id_photo The databases: CREATE TABLE IF NOT EXISTS `photos` ( `id` int(10) NOT NULL AUTO_INCREMENT, `photo_filename` varchar(50) NOT NULL, `photo_camera` varchar(150) NOT NULL, `photo_taken` datetime NOT NULL, `photo_resolution` varchar(10) NOT NULL, `photo_exposure` varchar(10) NOT NULL, `photo_iso` varchar(3) NOT NULL, `photo_fnumber` varchar(10) NOT NULL, `photo_focallength` varchar(10) NOT NULL, `post_coordinates` text NOT NULL, `post_description` text NOT NULL, `post_uploaded` datetime NOT NULL, `post_edited` datetime NOT NULL, `checkbox_approxcoor` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) CREATE TABLE IF NOT EXISTS `viewers` ( `id` int(10) NOT NULL AUTO_INCREMENT, `id_photo` int(10) DEFAULT '0', `ipaddress` text NOT NULL, `date_viewed` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) The data in viewers looks like this: (1, 85, '3892a0ab97d6ff325f285b27b847070f', '2012-06-21 22:49:25'), (2, 84, '3892a0ab97d6ff325f285b27b847070f', '2012-06-21 22:49:25'), (3, 85, '3892a0ab97d6ff325f285b27b847070f', '2012-06-21 22:49:25'); One single row from the database for photos to understand how the rows looks like in this database: (85, 'P1170986.JPG', 'Panasonic DMC-LX3', '2012-06-19 18:00:40', '3968x2232', '10/8000', '80', '50/10', '51/10', '', '', '2012-06-19 18:45:17', '0000-00-00 00:00:00', '0') At the moment the SQL only prints the photo with ID 84. In this case it's wrong - it should print out the photo with ID 85. How can I fix this problem? Thanks in advance.

    Read the article

  • CVS update doesn't fetch most recent commit

    - by mizipzor
    I just commited changes to a file (bringing it to revision 1.3). I then updated the file and to my surprise I got back revision 1.2 (how the file looked before my commit). Checking the history if the file shows that there is a revision 1.3 (most recent) and a 1.2 before that (which is identical to my local copy). Ive tried removing the file and updating the folder, causing the file to be downloaded again. Ive also tried fetching a clean copy of the file of HEAD. Clearing cache and fetching HEAD doesnt work. But forcing an update to revision 1.3 explicitly does. But doing a normal update after that causes it to go back to revision 1.2. This is on a Windows XP machine, server is also a Windows box. Im using TortoiseCVS. Does anyone know what could be causing this? (If you dont know how to fix it, I will award bonus points to anyone that can tell me why CVS broke and, hopefully, how horrible it will be to fix it. I want to add it to my list so that maybe some day I can convince my colleagues to finally give it up in favor of a more modern VCS.)

    Read the article

  • how to fetch exact string from a text file

    - by user136104
    Hi All, here is me requirement. I have one text file and I need to get exact specified string from that file C:>type small.txt | find "small2" small2 small22 small20 C:>type small.txt small2 small22 small20 C:>type small.txt | find "small2" small2 small22 small20 C:\ Here it is giving all the words instead of only "small2" Plz help me in this.. it's urgent Thanks in advance

    Read the article

  • Fetch image from folder via datatable does not work after placing image in subdirectory

    - by Arnold Bishkoff
    I am having trouble wrapping my head around the following I have code that fetches an image via smarty in a line img src="getsnap.php?picid={$data[$smarty.section.sec.index].picno|default:$nextpic}&typ=pic&width={$config.disp_snap_width}&height={$config.disp_snap_height}" class="smallpic" alt="" / this works if i pull the image from /temp/userimages/userid/imageNo.ext but because an OS can segfault if you store too many folders or images in a directory i have code that assigns the user image to a subdirectory based upon division of a subdir per 1000 userids. so in thise case i have user id 94 whos images get stored in /siteroot/temp/userimages/000000/94/pic_1.jpg (through 10) or tn_1 (through 10).jpg here is the code for getsnap.php <?php ob_start(); if ( !defined( 'SMARTY_DIR' ) ) { include_once( 'init.php' ); } include('core/snaps_functions.php'); if (isset($_REQUEST['username']) && $_REQUEST['username'] != '') { $userid = $osDB-getOne('select id from ! where username = ?',array(USER_TABLE, $_REQUEST['username']) ); } else { // include ( 'sessioninc.php' ); if( !isset($_GET['id']) || (isset($_GET['id'])&& (int)$_GET['id'] <= 0 ) ) { $userid = $_SESSION['UserId']; } else { $userid = $_GET['id']; } } if (!isset($_GET['picid']) ) { if ((isset($_REQUEST['type']) && $_REQUEST['type'] != 'gallery') || !isset($_REQUEST['type']) ) { $defpic = $osDB-getOne('select picno from ! where userid = ? and ( album_id is null or album_id = ?) and default_pic = ? and active = ? ',array(USER_SNAP_TABLE, $userid,'0','Y','Y' ) ); if ($defpic != '') { $picid = $defpic; } else { $picid = $osDB-getOne('select picno from ! where userid = ? and ( album_id is null or album_id = ?) and active=? order by rand()',array(USER_SNAP_TABLE, $userid,'0','Y' ) ); } unset( $defpic); } } else { $picid = $_GET['picid']; } $typ = isset( $_GET['typ'])?$_GET['typ']:'pic' ; $cond = ''; if ( ($config['snaps_require_approval'] == 'Y' || $config['snaps_require_approval'] == '1') && $userid != $_SESSION['UserId'] ) { $cond = " and active = 'Y' "; } $sql = 'select * from ! where userid = ? and picno = ? '.$cond; //Get the pic $row =& $osDB-getRow ( $sql, array( USER_SNAP_TABLE, $userid, $picid ) ); //Okay pic was found in the DB, Lets actually do something // $id = $userid; $dir = str_pad(($id - ($id % 1000))/100000,6,'0',STR_PAD_LEFT); $zimg = USER_IMAGES_DIR.$dir; $img = getPicture($zimg, $userid, $picid, $typ, $row); //$img = getPicture($userid, $picid, $typ, $row); //$img = getPicture($dir, $userid, $picid, $typ, $row); $ext = ($typ = 'tn')?$row['tnext']:$row['picext']; // Now pic is built as // something pic_x.ext ie pic_2.jpg if ( $img != '' && ( ( hasRight('seepictureprofile') && ( $config['snaps_require_approval'] == 'Y' && $row['active'] == 'Y' ) ||$config['snaps_require_approval'] == 'N' ) || $userid == $_SESSION['UserId'] ) ) { $img2 = $img; //$img2 = $dir.'/'.$img; } else { $gender = $osDB-getOne( 'select gender from ! where id = ?', array( USER_TABLE, $userid ) ) ; if ($gender == 'M') { $nopic = SKIN_IMAGES_DIR.'male.jpg'; } elseif ($gender == 'F') { $nopic = SKIN_IMAGES_DIR.'female.jpg'; } elseif ($gender == 'D') { $nopic = SKIN_IMAGES_DIR.'director.jpg'; } $img2 = imagecreatefromjpeg($nopic); $ext = 'jpg'; } ob_end_clean(); header("Pragma: public"); header("Content-Type: image/".$ext); header("Content-Transfer-Encoding: binary"); header("Cache-Control: must-revalidate"); $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() - 30) . " GMT"; header($ExpStr); $id = $userid; $dir = str_pad(($id - ($id % 1000))/100000,6,'0',STR_PAD_LEFT); $zimg = USER_IMAGES_DIR.$dir; //header("Content-Disposition: attachment; filename=profile_".$userid."_".$typ.".".$ext); //header("Content-Disposition: attachment; filename=$dir.'/'.profile_".$userid."".$typ.".".$ext); //header("Content-Disposition: attachment; filename=profile"$dir".'/'.".$userid."_".$typ.".".$ext); header("Content-Disposition: attachment; filename=profile_".$userid."_".$typ.".".$ext); /* if ($_SESSION['browser'] != 'MSIE') { header("Content-Disposition: inline" ); } */ if ($ext == 'jpg') { imagejpeg($img2); } elseif ($ext == 'gif') { imagegif($img2); } elseif ($ext == 'png') { imagepng($img2); } elseif ($ext == 'bmp') { imagewbmp($img2); } imagedestroy($img2); ?

    Read the article

  • how to fetch data from multiple tables MySQL

    - by faisal
    hi all, I am looking some help in php+MySQL+jquery I have 2 tables table1 table 1 have 4 colume (id, title, desc, thumb_img) tabel2 table 2 have 3 colume(id, table1id, img) I just want to compare 2 table with the value of $_get['QS']; and show the records from both (title, desc, img) Looking forward for the help.:)

    Read the article

  • How to fetch parameters when using the Apache Commons CLI library

    - by Mridang Agarwalla
    I'm using the Apache Commons CLI to handle command line arguments in Java. I've figured out my way around it to a decent extent but I need a little help. I've declared the a and b options and I'm able to access the value using CommandLine.getOptionValue. Usage: myapp [OPTION] [DIRECTORY] Options: -a Option A -b Option B How do I declare and access the DIRECTORY variable? Thank you.

    Read the article

  • improve my python program to fetch the desire rows by using if condition

    - by user2560507
    unique.txt file contains: 2 columns with columns separated by tab. total.txt file contains: 3 columns each column separated by tab. I take each row from unique.txt file and find that in total.txt file. If present then extract entire row from total.txt and save it in new output file. ###Total.txt column a column b column c interaction1 mitochondria_205000_225000 mitochondria_195000_215000 interaction2 mitochondria_345000_365000 mitochondria_335000_355000 interaction3 mitochondria_345000_365000 mitochondria_5000_25000 interaction4 chloroplast_115000_128207 chloroplast_35000_55000 interaction5 chloroplast_115000_128207 chloroplast_15000_35000 interaction15 2_10515000_10535000 2_10505000_10525000 ###Unique.txt column a column b mitochondria_205000_225000 mitochondria_195000_215000 mitochondria_345000_365000 mitochondria_335000_355000 mitochondria_345000_365000 mitochondria_5000_25000 chloroplast_115000_128207 chloroplast_35000_55000 chloroplast_115000_128207 chloroplast_15000_35000 mitochondria_185000_205000 mitochondria_25000_45000 2_16595000_16615000 2_16585000_16605000 4_2785000_2805000 4_2775000_2795000 4_11395000_11415000 4_11385000_11405000 4_2875000_2895000 4_2865000_2885000 4_13745000_13765000 4_13735000_13755000 My program: file=open('total.txt') file2 = open('unique.txt') all_content=file.readlines() all_content2=file2.readlines() store_id_lines = [] ff = open('match.dat', 'w') for i in range(len(all_content)): line=all_content[i].split('\t') seq=line[1]+'\t'+line[2] for j in range(len(all_content2)): if all_content2[j]==seq: ff.write(seq) break Problem: but istide of giving desire output (values of those 1st column that fulfile the if condition). i nead somthing like if jth of unique.txt == ith of total.txt then write ith row of total.txt into new file.

    Read the article

  • Fetch and load a whole page with AJAX

    - by nimo
    I realize that it's generally not a good idea to do this but the reason why I want to is because it's a really heavy page and I want to show the user progress of the download and when it's done load the page. I can either do this with some kind of spinner but is it possible for me to show the actual progress? Can I see how much and what data has been downloaded? Let's say I use jQuery for the AJAX-request how do I do this? If you have other suggestions please feel free to suggest.

    Read the article

  • What is the most efficient approach to fetch category tree, products, brands, counts by subcategory

    - by alex227
    Symfony 1.4 + Doctrine 1.2. What is the best way to minimize the number of queries to retrieve products, subcategories of current category, product counts by subcategory and brand for the result set of the query below? Categories are a nested set. Here is my query: $q = Doctrine_Query::create() ->select('c.*, p.product,p.price, b.brand') ->from('Category c') ->leftJoin('c.Product p') ->leftJoin('p.Brand b') ->where ('c.root_id = ?', $this->category->getRootId()) ->andWhere('c.lft >= ?', $this->category->getLft()) ->andWhere('c.rgt <= ?', $this->category->getRgt()) ->setHydrationMode(Doctrine_Core::HYDRATE_ARRAY); $treeObject = Doctrine::getTable('Category')->getTree(); $treeObject->setBaseQuery($q); $this->treeObject = $treeObject; $treeObject->resetBaseQuery(); $this->products = $q->execute();

    Read the article

  • continuously fetch data from database using JAVA

    - by deathcaller
    Hi all, I've a scenario where my java program has to continuously communicate with the database table, example my java program has to get the data of my table when new rows are added to it at runtime. There should be continuous communication between my program and database. if the table has 10 rows initially and 2 rows are added by the user, it must detect this and return the rows. My program shouldn't use AJAX and timers. Please Help.

    Read the article

  • problem during data fetch

    - by nectar
    here is my code $sql="SELECT * FROM $tbl_name WHERE ownerId='$UserId'"; $result=mysql_query($sql,$link)or die(mysql_error()); $row = mysql_fetch_array($result, MYSQL_ASSOC); <?php while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<tr>"; echo "<td>".$row['pinId']."</td>"; echo "<td>".$row['usedby']."</td>"; echo "<td>".$row['status']."</td>"; echo "</tr>"; } ?> it is ignoring the first record means if 4 rows are in $row its ignoring the 1st one rest three are coming on page. ownerId is not primary key.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >