Search Results

Search found 17924 results on 717 pages for 'z order'.

Page 141/717 | < Previous Page | 137 138 139 140 141 142 143 144 145 146 147 148  | Next Page >

  • postgres min function performance

    - by wutzebaer
    hi i need the lowest value for runnerId this query: SELECT "runnerId" FROM betlog WHERE "marketId" = '107416794' ; takes 80ms (1968 result rows) this SELECT min("runnerId") FROM betlog WHERE "marketId" = '107416794' ; takes 1600ms is there a faster way to find the minimum, or should i calc the min in my java programm? "Result (cost=100.88..100.89 rows=1 width=0)" " InitPlan 1 (returns $0)" " -> Limit (cost=0.00..100.88 rows=1 width=9)" " -> Index Scan using runneridindex on betlog (cost=0.00..410066.33 rows=4065 width=9)" " Index Cond: ("runnerId" IS NOT NULL)" " Filter: ("marketId" = 107416794::bigint)" CREATE INDEX marketidindex ON betlog USING btree ("marketId" COLLATE pg_catalog."default"); another idea SELECT "runnerId" FROM betlog WHERE "marketId" = '107416794' ORDER BY "runnerId" LIMIT 1 >1600ms SELECT "runnerId" FROM betlog WHERE "marketId" = '107416794' ORDER BY "runnerId" >>100ms how can a limit slow the query down?

    Read the article

  • Getting a query to index seek (rather than scan)

    - by PaulB
    Running the following query (SQL Server 2000) the execution plan shows that it used an index seek and Profiler shows it's doing 71 reads with a duration of 0. select top 1 id from table where name = '0010000546163' order by id desc Contrast that with the following with uses an index scan with 8500 reads and a duration of about a second. declare @p varchar(20) select @p = '0010000546163' select top 1 id from table where name = @p order by id desc Why is the execution plan different? Is there a way to change the second method to seek? thanks EDIT Table looks like CREATE TABLE [table] ( [Id] [int] IDENTITY (1, 1) NOT NULL , [Name] [varchar] (13) COLLATE Latin1_General_CI_AS NOT NULL) Id is primary clustered key There is a non-unique index on Name and a unique composite index on id/name There are other columns - left them out for brevity

    Read the article

  • Problem with multi-table MySQL query

    - by mahle
    I have 3 tables. Here is the relevant information needed for each. items prod_id order_id item_qty orders order_id order_date order_status acct_id accounts acct_id is_wholesale items is linked to order by the order_id and orders is linked to accounts via acct_id I need to sum item_qty for all items where prod_id=464 and the order stats is not 5 and where the is_wholesale is 0 and the order_date is between two dates. Im struggling with this and would appreciate any help. Here is what I have but it's not working correctly: SELECT SUM(items.item_qty) as qty FROM items LEFT JOIN orders ON orders.order_id = items.order_id LEFT JOIN accounts on orders.acct_id = accounts.acct_id WHERE items.prod_id =451 AND orders.order_date >= '$from_date' AND orders.order_date <= '$to_date' AND orders.order_status <>5 AND accounts.is_wholesale=0; Again, any help would be greatly appreciated!

    Read the article

  • Hibernate criterion Projection alias not being used

    - by sbzoom
    Do Hibernate Projection aliases even work? I could swear it just doesn't. At least, it doesn't do what I would expect it to do. Here is the java: return sessionFactory.getCurrentSession().createCriteria( PersonProgramActivity.class ).setProjection( Projections.projectionList().add( Projections.alias( Projections.sum( "numberOfPoints" ), "number_of_points" ) ).add( Projections.groupProperty( "person.id" ) ) ).setFirstResult( start ).setFetchSize( size ).addOrder( Order.desc( "numberOfPoints" ) ).list(); Here is the SQL that it generates: select sum(this_.number_of_points) as y0_, this_.person_id as y1_ from PERSON_PROGRAM_ACTIVITY this_ group by this_.person_id order by this_.number_of_points desc It doesn't seem to use the alias at all. I would think setting the alias would mean that "sum(this_.number_of_points)" would be aliased as "number_of_points" and not "y0_". Is there some trick I am missing? Thanks.

    Read the article

  • Placing .htaccess file in var/www folder messes my website up...

    - by Camran
    I am playing with mod_rewrite now, and have successfully enabled it. However, I need to put a htaccess file inside var/www/ in order to achieve what I want, which is to rename Urls simply... When I place it my website becomes very strange and nothing basically works... Is there any code I need to put into the htaccess file in order for things to act normally? Here is the htaccess file I have so far: Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteCond %{REQUEST_URI} !^/ad\.php RewriteRule ^(.*)$ ad.php?ad_id=$1 [L] My DocumentRoot is also set to var/www/ and my entire website root is there... (index.html etc etc)... What am I missing about the htaccess? If you need more input let me know...

    Read the article

  • Changed the AllowOverride to All and still nothing

    - by Asaf
    I tried to write a .htaccess file on my local pc's website, I've realized I need to set AllowOverride All instead of None searched, found the file /etc/apache2/conf.d/security in the file I found #<Directory /> #AllowOverride None #Order Deny,Allow #Deny from all #</Directory> changed it to <Directory /> AllowOverride All Order Deny,Allow Deny from all </Directory> typed service apache2 restart and... .htaccess still didn't work :I the file by the way, holds one line, deny from all.

    Read the article

  • How many Stored Procedures created everyday ( problem in converting Datetime )?

    - by Space Cracker
    I make a query that return to me the count of Stored Procedure that created everyday as follow SELECT convert(varchar, crdate, 103) as Date,Count(*) as Counter FROM sysobjects WHERE (xtype = 'p') AND (name NOT LIKE 'dt%') Group by convert(varchar, crdate, 103) and its already work but dates appear in string format that i can't order it such as below 01/03/2010 3 01/04/2008 4 01/05/2010 5 01/11/2008 1 01/12/2008 4 02/03/2008 1 02/03/2010 2 02/04/2008 4 02/05/2010 2 02/11/2008 2 02/11/2009 2 02/12/2008 4 03/01/2010 1 03/02/2010 2 03/03/2010 2 03/04/2008 2 03/04/2010 2 03/05/2008 1 03/05/2010 2 I want to make that in which date is in datetime format that i can make order by successfully, i tried convert(datetime, crdate, 103) but it show Full date any idea of how to do ?

    Read the article

  • In SQL Server 2000, how to delete the specified rows in a table that does not have a primary key?

    - by Yousui
    Hi, Let's say we have a table with some data in it. IF OBJECT_ID('dbo.table1') IS NOT NULL BEGIN DROP TABLE dbo.table1; END CREATE TABLE table1 ( DATA INT ); --------------------------------------------------------------------- -- Generating testing data --------------------------------------------------------------------- INSERT INTO dbo.table1(data) SELECT 100 UNION ALL SELECT 200 UNION ALL SELECT NULL UNION ALL SELECT 400 UNION ALL SELECT 400 UNION ALL SELECT 500 UNION ALL SELECT NULL; How to delete the 2nd, 5th, 6th records in the table? The order id defined by the following query. SELECT data FROM dbo.table1 ORDER BY data DESC; Note, this is in SQL Server 2000 environment. Thanks.

    Read the article

  • display items vertically

    - by shawn swanson
    This is my code: <?php while($fetch_cat = mysql_fetch_array($rescat)) { $per_cnt++; ?> <li style="margin-left:10px;"> <a href="sub_cat.php?cat_id=<?php echo $fetch_cat['cat_id'];?>" style="color:#431603;text-decoration:none;"><?php echo stripslashes($fetch_cat['category_name']);?> </a> </li> <?php } ?> This is the output I am getting- alphabetical order horizontally: A B C D E F G H I J This is what I want to show- alphabetical order vertically: A E H B F I C G J D Please help. Thanks

    Read the article

  • How to get a List ordered by the List it's filtered by?

    - by DaveDev
    I have a method as follows. It returns a list of MyTypes which appear to be ordered by myType.Id ascending by default. public List<MyType> GetMyTypes(List<int> ids) { return (from myType in db.MyTypes where ids.Contains(myType.Id) select new MyType { MyValue = myType.MyValue }).ToList(); } So if ids contains 302 300 301 the List returned contains items in ascending order. What do I need to do to return List<MyType> in the order of ids? Thanks edit: I've tried orderby ids.IndexOf(myType.Id) but it throws the exception Method 'Int32 IndexOf(Int32)' has no supported translation to SQL.

    Read the article

  • Loading multiple embedded flash apps onto an HTML page- problem with ordering

    - by shudson250
    We need to load an embedded version of a site written in Flash, and not originally designed to load multiple instances of itself, on a HTML page. The specific issue is how to get them to load in order when embedded, given that they are all being opened by the same instance of the flash player. It's a complicated mapping application, and at the moment, the maps and data get intermixed as the session variables are overwritten by another instance starting to load before the previous one has finished. We need a way to have them load sequentially, one finishing before another starts to load. The most we can specify in the URL is an &order=1 or similar. We have PHP and SQL on the backend. Edit: The embedded versions are being loaded in an iFrame of a parent site. One php file loads one swf, as many times as the parent site desires.

    Read the article

  • MySQL is there a Single Select to Query Various Unrelated Values from a database?

    - by zzapper
    I saw somewhere what seemed to be nested selects, one "master" select on the "outside" and a series of selects inside- is this possible? I'm not talking about joins as there is particular relation between the selects. I seem not to be explaining myself very well. I want to do a single query which will pull out a series of stats from various tables latest order, latest customer, largest order. Obviously I can do that with a series of selects. The example I saw was something like select ( select ... from tbl_1 where .., select ... from tbl_2 where .., select ... from tbl_3 where .., ... )

    Read the article

  • Mysql select most frequent and sort alphabetically

    - by user2605793
    I am trying to select the most common 100 names from a table then display the list showing the names and count. I want the user to be able to re-sort the list alphabetically rather than based on count. I thought the following code would do it. It works for the default sort by count but fails on the sort alphabetically. The line "$count = mysql_num_rows($table);" gives an error: mysql_num_rows() expects parameter 1 to be resource, boolean given. Any help would be greatly appreciated. // Get most popular surnames echo '<h2>Most Common Surnames</h2>'; if ($sort == "") { // default sort by count echo '<a href="http://mysite/names.php?id='.$id.'&sort=name">Sort by name</a><br>'; $query = "SELECT family_name, COUNT(*) as count FROM namefile WHERE record_key = $id GROUP BY family_name ORDER BY count DESC LIMIT 100"; } else { // sort alphabetically echo '<a href="http://mysite/names.php?id='.$id.'">Sort by count</a><br>'; $query = "SELECT * FROM ( SELECT family_name, COUNT(*) as count FROM namefile WHERE record_key = $id GROUP BY family_name ORDER BY count DESC LIMIT 100) AS alpha ORDER BY family_name"; } $table = mysql_query($query); $count = mysql_num_rows($table); $tot = 0; $i = 0; echo '<table><tr>'; while ($tot < $count2) { $rec2 = mysql_fetch_array($table2); echo '<td>'.$rec2[0].'</td><td>'.$rec2[1].'</td><td width="40">&nbsp;</td><td>'; if ($i++ == 6) { echo '</tr><tr>'; $i = 0; } $tot++; } echo '</tr></table><br>'; UPDATE: I needed to add "AS alpha" to give the outer select a unique name. (alpha is just a random name I made up.) It now works perfectly. Code updated for the benefit of any others who need something similar.

    Read the article

  • question about random select

    - by davit-datuashvili
    here is code print number in decreasing order import java.util.*; public class select { public static void Select(int m,int n){ Random r=new Random(); if (m>0) if (r.nextInt(0x3fff8001) % n <m ){ System.out.println(n-1); Select(m-1,n-1); } else{ Select(m,n-1); } } public static void main(String[]args){ int m=35; int n=200; Select(m,n); } } and question is how to changes code such that print number in increasing order? please help

    Read the article

  • which one is a faster/better sql practice?

    - by artsince
    Suppose I have a 2 column table (id, flag) and id is sequential. I expect this table to contain a lot of records. I want to periodically select the first row not flagged and update it. Some of the records on the way may have already been flagged, so I want to skip them. Does it make more sense if I store the last id I flagged and use it in my select statement, like select * from mytable where id > my_last_id order by id asc limit 1 or simply get the first unflagged row, like: select * from mytable where flagged = 'F' order by id asc limit 1 Thank you!

    Read the article

  • Polymorphism in Rails

    - by Newy
    Say I have two models, Apples and Oranges, and they are both associated with a description in a Text model. Text is a separate class as I'd like to keep track of the different revisions. Is the following correct? Is there a better way to do this? [Apple] has_one :text, :as => :targit, :order => 'id DESC' has_many :revisions, :class_name => 'Text', :as => :targit, :order => 'id', :dependent => :destroy [Text] belongs_to :targit, :polymorphic => true

    Read the article

  • Python read files in directory and concatenate

    - by JJ Beck
    I want to write a Python script that searches all folders in the current directory, looks for all .txt files, and creates a file that is a concatenation of all those files (in any order) in the current directory. If folders have subfolders, it should not search those subfolders. An example is main_folder folder_1 sub_folder file1.txt file2.txt folder_2 file3.txt The script is placed inside main_folder. It should create a file that is a concatenation of file2.txt and file3.txt (in any order) inside main_folder. My question is: How can I tell Python to traverse through the folders, look for .txt files, without going into the subfolders?

    Read the article

  • How to check if the sum of some records equals the difference between two other records in t-sql?

    - by Dan Appleyard
    I have a view that contains bank account activity. ACCOUNT BALANCE_ROW AMOUNT SORT_ORDER 111 1 0.00 1 111 0 10.00 2 111 0 -2.50 3 111 1 7.50 4 222 1 100.00 5 222 0 25.00 6 222 1 125.00 7 ACCOUNT = account number BALANCE_ROW = either starting or ending balance would be 1, otherwise 0 AMOUNT = the amount SORT_ORDER = simple order to return the records in the order of start balance, activity, and end balance I need to figure out a way to see if the sum of the non balance_row rows equal the difference between the ending balance and the starting balance. The result for each account (1 for yes, 0 for no) would be simply added to the resulting result set. Example: Account 111 had a starting balance of 0.00. There were two account activity records of 10.00 and -2.5. That resulted in the ending balance of 7.50. I've been playing around with temp tables, but I was not sure if there is a more efficient way of accomplishing this. Thanks for any input you may have!

    Read the article

  • My tricky SQL Update query not working so well.

    - by Spooks
    I am trying to update a table in my database with another row from another table. I have two parameters one being the ID and another being the row number (as you can select which row you want from the GUI) this part of the code works fine, this returns one column of a single row. (select txtPageContent FROM (select *, Row_Number() OVER (ORDER BY ArchiveDate asc) as rowid from ARC_Content Where ContentID = @ContentID) as test Where rowid = @rowID) its just when i try to add the update/set it won't work. I am probably missing something update TBL_Content Set TBL_Content.txtPageContent = (select txtPageContent FROM (select *, Row_Number() OVER (ORDER BY ArchiveDate asc) as rowid from ARC_Content Where ContentID = @ContentID) as test Where rowid = @rowID) Thanks for the help! (i have tried top 1 with no avail)

    Read the article

  • JS Split ( ) to check if substring exists in Array

    - by Javacadabra
    I have an array of products that are stored as Strings in this format productname:quantity. The issue I am running into is that if a user adds one product with a quantity of x it is inserted into the array as it should. However, if they then decide to add more of a particular product a new entry is made into the array instead of checking if the product already exists and adjusting the quantity to the new value. oldQty + newQty. For example this is my array: ["CBL202659/A:1","OUTER9:1","PALLET CARDS:1"] If I add another PALLET CARDS product it creates a new entry rather than updating the quantity of the existing item to 2. New array ["CBL202659/A:1","OUTER9:1","PALLET CARDS:1","PALLET CARDS:1"] I would like the array to end up like this: - updating the quantity ["CBL202659/A:1","OUTER9:1","PALLET CARDS:2"] Currently this is my code: I use the split() method to seperate the String where a colon occurs and store the product name and quantity in two seperate variables. $(".orderBtn").click(function(event){ //Show the order Box $(".order-alert").show(); event.preventDefault(); //Create the Array var productArray = []; //Get reference to the product clicked var stockCode = $(this).closest('li').find('.stock_code').html(); //Get reference to the quantity selected var quantity = $(this).closest('li').find('.order_amount').val(); var item = stockCode + ":" + quantity; var itemCheck = stockCode + ":"; if(quantity == 0){ console.log("Quantity must be greater than 0") }else{ //If no Cookie exists, create one and add the Array if ($.cookie('order_cookie') === undefined) { console.log("CREATE NEW COOKIE"); //Add items to Array productArray.push(item); //Add Array to Cookie $.cookie('order_cookie', JSON.stringify(productArray), { expires: 1, path: '/' }); //If the Cookie already exists do this } else { productArray = JSON.parse($.cookie('order_cookie'));//get ref to array if(productArray.indexOf(itemCheck)!= -1){//It exists so update qty console.log("EXISTS... updating item: " + itemCheck); //var index = productArray.indexOf(item); //var update = productArray[index].split(":"); //var name = update[0]; //var oldQty = update[1]; //console.log(name + ":" + oldQty); //productArray[index] = item; }else{//It does not exist, so add to array console.log("Does not exist... adding new item: " + item); //Append items onto the Array productArray.push(item); } //Update the Cookie $.cookie('order_cookie', JSON.stringify(productArray), { expires: 1, path: '/' }); console.log($.cookie('order_cookie')); } //Display the number of items in the Array in the Order Box $('#order_counter').html(productArray.length); } }); I suppose the real question I am asking here, is if it is possible to search the array for a subString - containing productname: ??

    Read the article

  • undefined GET id?

    - by Azzyh
    <?php $s = $_GET["s"]; if($s) { $hent_b = mysql_query("SELECT * FROM member_battles WHERE state = '1' ORDER BY id DESC LIMIT 0,200") or die(mysql_error()); }else{ $hent_b = mysql_query("SELECT * FROM member_battles WHERE state = '0' ORDER BY id DESC LIMIT 0,200") or die(mysql_error()); } while($vis = mysql_Fetch_array($hent_b)) { ?> I have this now i want when i enter my site (index.php) it should not come up undefined $_GET["s"]; how do i do this? but i want when you do index.php?s then it should change the query

    Read the article

  • Efficient implementation of exclusive execution

    - by n0weak
    I have an ObjectManager class that is used to process payments. It is wrapped over the Order entities, so new instance has to be created when processing is required. I need to prevent the situation when several ObjectManager instances are dealing with the same order simultaneously (it happend once because of some errors on the remote payment processing center, somehow they called our callback urls twice). I'd love to get an advice how to implement it more efficiently. For now, I am thinking about something like that: public class OrderManager{ private static final CopyOnWriteArrayList<Integer> LOCKER = new CopyOnWriteArrayList<Integer>(); private static synchronized boolean tryLock(Integer key) { return LOCKER.addIfAbsent(key); } private static void releaseLock(Integer key) { LOCKER.remove(key); } public void processPayment(Integer orderId) throws Exception{ if (!tryLock(orderId)) { return; } try { //operate } finally { releaseLock(orderId); } } //remainder omitted }

    Read the article

  • More efficient SQL than using "A UNION (B in A)"?

    - by machinatus
    Edit 1 (clarification): Thank you for the answers so far! The response is gratifying. I want to clarify the question a little because based on the answers I think I did not describe one aspect of the problem correctly (and I'm sure that's my fault as I was having a difficult time defining it even for myself). Here's the rub: The result set should contain ONLY the records with tstamp BETWEEN '2010-01-03' AND '2010-01-09', AND the one record where the tstamp IS NULL for each order_num in the first set (there will always be one with null tstamp for each order_num). The answers given so far appear to include all records for a certain order_num if there are any with tstamp BETWEEN '2010-01-03' AND '2010-01-09'. For example, if there were another record with order_num = 2 and tstamp = 2010-01-12 00:00:00 it should not be included in the result. Original question: Consider an orders table containing id (unique), order_num, tstamp (a timestamp), and item_id (the single item included in an order). tstamp is null, unless the order has been modified, in which case there is another record with identical order_num and tstamp then contains the timestamp of when the change occurred. Example... id order_num tstamp item_id __ _________ ___________________ _______ 0 1 100 1 2 101 2 2 2010-01-05 12:34:56 102 3 3 113 4 4 124 5 5 135 6 5 2010-01-07 01:23:45 136 7 5 2010-01-07 02:46:00 137 8 6 100 9 6 2010-01-13 08:33:55 105 What is the most efficient SQL statement to retrieve all of the orders (based on order_num) which have been modified one or more times during a certain date range? In other words, for each order we need all of the records with the same order_num (including the one with NULL tstamp), for each order_num WHERE at least one of the order_num's has tstamp NOT NULL AND tstamp BETWEEN '2010-01-03' AND '2010-01-09'. It's the "WHERE at least one of the order_num's has tstamp NOT NULL" that I'm having difficulty with. The result set should look like this: id order_num tstamp item_id __ _________ ___________________ _______ 1 2 101 2 2 2010-01-05 12:34:56 102 5 5 135 6 5 2010-01-07 01:23:45 136 7 5 2010-01-07 02:46:00 137 The SQL that I came up with is this, which is essentially "A UNION (B in A)", but it executes slowly and I hope there is a more efficient solution: SELECT history_orders.order_id, history_orders.tstamp, history_orders.item_id FROM (SELECT orders.order_id, orders.tstamp, orders.item_id FROM orders WHERE orders.tstamp BETWEEN '2010-01-03' AND '2010-01-09') AS history_orders UNION SELECT current_orders.order_id, current_orders.tstamp, current_orders.item_id FROM (SELECT orders.order_id, orders.tstamp, orders.item_id FROM orders WHERE orders.tstamp IS NULL) AS current_orders WHERE current_orders.order_id IN (SELECT orders.order_id FROM orders WHERE orders.tstamp BETWEEN '2010-01-03' AND '2010-01-09');

    Read the article

  • Mysql slowing down my application

    - by user2985991
    my application is taking ages to load because of my database isnt located on my computer.. Anyone have any idea to how improve my performance? public Form1() { Splash splash = new Splash(); splash.Show(); InitializeComponent(); Load(); public void Load() { db.SelectTeam(); db.SelectMatches(); } On db.SelectTeam and SelectMatches I get everything I need from mysql and put into lists... Sorry if it's confusing, but I don't know what to do, and sorry for my bad english EDIT: Here are the querys string query = "SELECT * FROM teams ORDER BY name"; string query = "SELECT * FROM matches ORDER BY date ASC";

    Read the article

< Previous Page | 137 138 139 140 141 142 143 144 145 146 147 148  | Next Page >