Search Results

Search found 22901 results on 917 pages for 'query bug'.

Page 31/917 | < Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >

  • MySQL Query order by numer of rows?

    - by Clemens
    hi, i have a mysql table for votes. there's am id, a project_id and a vote field (which is 1 if a specific project is voted). now i want to generate a ranking from those entries. is there a way to get the number of votes for each project_id and automatically sort the entries by the number of TRUE votes of a project with a single mysql query? Or do you know a php way? e.g. ID - Project ID - Vote 1 - 2 - 1 2 - 2 - 1 3 - 1 - 1 == Project Nr. 2 has 2 Votes Project Nr. 1 has 1 Vote Thanks in advance!

    Read the article

  • More strict query yields more results?

    - by Mark
    I've got a query that looks like this affiliates = User.objects.annotate(referral_count=Count('referrals')).filter(referral_count__gt=0) But when I restrict it more by adding referrals__user__date_joined__gt=start_date to the filter, I get even higher referral counts. I'm trying to count the number of people a user has referred within a time period. The relevant model looks like this: class Profile(models.Model): user = models.ForeignKey(User, unique=True, related_name='profile') referred_by = models.ForeignKey(User, null=True, blank=True, related_name='referrals') In contrast, when I try it like this: affiliates = User.objects \ .exclude(referrals__user__date_joined__lte=sd, referrals__user__date_joined__gt=ed) \ .annotate(referral_count=Count('referrals')) \ .filter(referral_count__gt=0) The exclude statement seems to do nothing... the counts don't change (should be 0 if no referred users have joined within that time period, but it isn't).

    Read the article

  • Complicated MySQL query?

    - by Scott
    I have two tables: RatingsTable that contains a ratingname and a bit whether it is a positive or negative rating: Good 1 Bad 0 Fun 1 Boring 0 FeedbackTable that contains feedback on things...the person rating, the rating and the thing rated. The feedback can be determined if it's a positive or negative rating based on RatingsTable. Jim Chicken Good Jim Steak Bad Ted Waterskiing Fun Ted Hiking Fun Nancy Hiking Boring I am trying to write an efficient MySQL query for the following: On a page, I want to display the the top 'things' that have the highest proportional positive ratings. I want to be sure that the items from the feedback table are unique...meaning, that if Jim has rated Chicken Good 20 times...it should only be counted once. At some point I will want to require a minimum number of ratings (at least 10) to be counted for this page as well. I'll want to to do the same for highest proportional negative ratings, but I am sure I can tweak the one for positive accordingly.

    Read the article

  • Using a RegEx in a SQL Query

    - by Jim B
    Hey Everyone, Here's the situation I'm in: We have a field in our database that contains a 3 digit number, surrounded by some text. This number is actually a PK in another table, and I need to extract this out so I can implement a proper FK relationship. Here's an example of what would currently reside in the column: Some Text Goes Here - (305) Followed By Some More Text So, what I'm looking to do is extract the '305' from the column, and hopefully end up with a result that looks something like this (pseudo code) SELECT <My Extracted Value>, Original Column Text, Id FROM dbo.MyTable It seems to me that using a Regex match in my query is the most effective way to do this. Can anybody point me in the right direction?

    Read the article

  • Long-running Database Query

    - by JamesMLV
    I have a long-running SQL Server 2005 query that I have been hoping to optimize. When I look at the actual execution plan, it says a Clustered Index Seek has 66% of the cost. Execuation Plan Snippit: <RelOp AvgRowSize="31" EstimateCPU="0.0113754" EstimateIO="0.0609028" EstimateRebinds="0" EstimateRewinds="0" EstimateRows="10198.5" LogicalOp="Clustered Index Seek" NodeId="16" Parallel="false" PhysicalOp="Clustered Index Seek" EstimatedTotalSubtreeCost="0.0722782"> <OutputList> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="quoteDate" /> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="price" /> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="tenure" /> </OutputList> <RunTimeInformation> <RunTimeCountersPerThread Thread="0" ActualRows="1067" ActualEndOfScans="1" ActualExecutions="1" /> </RunTimeInformation> <IndexScan Ordered="true" ScanDirection="FORWARD" ForcedIndex="false" NoExpandHint="false"> <DefinedValues> <DefinedValue> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="quoteDate" /> </DefinedValue> <DefinedValue> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="price" /> </DefinedValue> <DefinedValue> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="tenure" /> </DefinedValue> </DefinedValues> <Object Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Index="[_dta_index_Indices_14_320720195__K5_K2_K1_3]" Alias="[I]" /> <SeekPredicates> <SeekPredicate> <Prefix ScanType="EQ"> <RangeColumns> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="HedgeProduct" ComputedColumn="true" /> </RangeColumns> <RangeExpressions> <ScalarOperator ScalarString="(1)"> <Const ConstValue="(1)" /> </ScalarOperator> </RangeExpressions> </Prefix> <StartRange ScanType="GE"> <RangeColumns> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="tenure" /> </RangeColumns> <RangeExpressions> <ScalarOperator ScalarString="[@StartMonth]"> <Identifier> <ColumnReference Column="@StartMonth" /> </Identifier> </ScalarOperator> </RangeExpressions> </StartRange> <EndRange ScanType="LE"> <RangeColumns> <ColumnReference Database="[wf_1]" Schema="[dbo]" Table="[Indices]" Alias="[I]" Column="tenure" /> </RangeColumns> <RangeExpressions> <ScalarOperator ScalarString="[@EndMonth]"> <Identifier> <ColumnReference Column="@EndMonth" /> </Identifier> </ScalarOperator> </RangeExpressions> </EndRange> </SeekPredicate> </SeekPredicates> </IndexScan> </RelOp> From this, does anyone see an obvious problem that would be causing this to take so long? Here is the query: (SELECT quotedate, tenure, price, ActualVolume, HedgePortfolioValue, Price AS UnhedgedPrice, ((ActualVolume*Price - HedgePortfolioValue)/ActualVolume) AS HedgedPrice FROM ( SELECT [quoteDate] ,[price] , tenure ,isnull(wf_1.[Risks].[HedgePortValueAsOfDate2](1,tenureMonth,quotedate,price),0) as HedgePortfolioValue ,[TotalOperatingGasVolume] as ActualVolume FROM [wf_1].[dbo].[Indices] I inner join ( SELECT DISTINCT tenureMonth FROM [wf_1].[Risks].[KnowRiskTrades] WHERE HedgeProduct = 1 AND portfolio <> 'Natural Gas Hedge Transactions' ) B ON I.tenure=B.tenureMonth inner join ( SELECT [Month],[TotalOperatingGasVolume] FROM [wf_1].[Risks].[ActualGasVolumes] ) C ON C.[Month]=B.tenureMonth WHERE HedgeProduct = 1 AND quoteDate>=dateadd(day, -3*365, tenureMonth) AND quoteDate<=dateadd(day,-3,tenureMonth) )A )

    Read the article

  • LINQ to XML query

    - by ile
    Here I had very similar xml structure, but now I have this: <Fields> <Company>My Company</Company> <Address2>Villa at beach</Address2> <Email2>[email protected]</Email2> <Mobile>333-888</Mobile> <ContactMethod>Facebook</ContactMethod> </Fields> And now I need the same output as on the given link: Company: My Company Address2: Villa at beach Email2: [email protected] What would be the query for it? Thanks, Ile

    Read the article

  • how to query with child relations to same table and order this correctly

    - by robertpnl
    Hi, Take this table: id name sub_id --------------------------- 1 A (null) 2 B (null) 3 A2 1 4 A3 1 The sub_id column is a relation to his owm table, to column ID. subid --- 0:1 --- id Now I have the problem to make a correctly SELECT query to show that the child rows (which sub_id is not null) directly selected under his parent row. So this must be a correctly order: 1 A (null) 3 A2 1 4 A3 1 2 B (null) A normal SELECT order the id. But how or which keyword help me to order this correctly? JOIN isn't possible I think because I want to get all the rows seperated. Because the rows will be displayed on a Gridview (ASP.Net) with EntityDataSource but the child rows must be displayed directly under his parent. Thank you.

    Read the article

  • SQL query not taking values more than 2100

    - by user175084
    SELECT MachineID, MachineName, count(ID) as Total, sum(Size) as TotalSize FROM Files join Machines on Files.MachineID = Machines.MachineID Where Files.MachineID In(sql.Append(string.Format("@MachineId{0}", i)); group by Files.MachineID,MachineName now when the machinId count is less than 2100 the query is performed and if it machines go above 2100 an error is thrown Error: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100. how do i make increase the limit or just avoid getting this error.. and put values in gridview thanks..

    Read the article

  • Help Forming An SQL Query That Selects The Max Difference Of Two Fields

    - by Frank
    I'm trying to select a record with the most effective votes. Each record has an id, the number of upvotes (int) and the number of downvotes (int) in a MySQL database. I know basic update, select, insert queries but I'm unsure of how to form a query that looks something like: SELECT * FROM topics WHERE MAX(topic.upvotes - topic.downvotes). Please excuse my made up SQL. The tutorials on SQL I find on the internet cover very basic stuff. Does anyone recommend a good book on this subject?

    Read the article

  • MSSql Query solution cum Suggestion Required

    - by Nirmal
    Hello All... I have a following scenario in my MSSql 2005 database. zipcodes table has following fields and value (just a sample): zipcode latitude longitude ------- -------- --------- 65201 123.456 456.789 65203 126.546 444.444 and "place" table has following fields and value : id name zip latitude longitude -- ---- --- -------- --------- 1 abc 65201 NULL NULL 2 def 65202 NULL NULL 3 ghi 65203 NULL NULL 4 jkl 65204 NULL NULL Now, my requirement is like I want to compare my zip codes of "place" table and update the available latitude and longitude fields from "zipcode" table. And there are some of the zipcodes which has no entry in "zipcode" table, so that should remain null. And the major issue is like I have more then 50,00,000 records in my db. So, query should support this feature. I have tried some of the solutions but unfortunately not getting proper output. Any help would be appreciated...

    Read the article

  • Can't get values from Sqlite DB using query

    - by Sana Joseph
    I used sqlite to populate a DB with some Tables in it. I made a function at another javascript page that executes the database & selects some values from the table. Javascript: function GetSubjectsFromDB() { tx.executeSql('SELECT * FROM Subjects', [], queryNSuccess, errorCB); } function queryNSuccess(tx, results) { alert("Query Success"); console.log("Returned rows = " + results.rows.length); if (!results.rowsAffected) { console.log('No rows affected!'); return false; } console.log("Last inserted row ID = " + results.insertId); } function errorCB(err) { alert("Error processing SQL: "+err.code); } Is there some problem with this line ? tx.executeSql('SELECT * FROM Subjects', [], queryNSuccess, errorCB); The queryNSuccess isn't called, neither is the errorCB so I don't know what's wrong.

    Read the article

  • ASP Classic Named Parameter in Paramaterized Query: Must declare the scalar variable

    - by My Alter Ego
    I'm trying to write a parameterized query in ASP Classic, and it's starting to feel like i'm beating my head against a wall. I'm getting the following error: Must declare the scalar variable "@something". I would swear that is what the hello line does, but maybe i'm missing something... <% OPTION EXPLICIT %> <!-- #include file="../common/adovbs.inc" --> <% Response.Buffer=false dim conn,connectionString,cmd,sql,rs,parm connectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Data Source=.\sqlexpress;Initial Catalog=stuff" set conn = server.CreateObject("adodb.connection") conn.Open(connectionString) set cmd = server.CreateObject("adodb.command") set cmd.ActiveConnection = conn cmd.CommandType = adCmdText cmd.CommandText = "select @something" cmd.NamedParameters = true cmd.Prepared = true set parm = cmd.CreateParameter("@something",advarchar,adParamInput,255,"Hello") call cmd.Parameters.append(parm) set rs = cmd.Execute if not rs.eof then Response.Write rs(0) end if %>

    Read the article

  • Help needed in AdventureWorks in a sql query.

    - by vaibhav
    I was just playing with adventureworks database in sqlserver. I got stuck in a query. I wanted to Select all titles from HumanResources.Employee which are either 'Male' or 'Female' but not both. i.e if title Accountant is Male and Female both I want to leave that title. I need only those titles where Gender is either Male or Female. I have done this till yet. select distinct(title) from humanresources.employee where gender='M' select distinct(title) from humanresources.employee where gender='F' Probably a join between these two queries, would work. But If you have any other solution, please let me know. It is not a homework. :) Thanks in advance.

    Read the article

  • Query a Hibernate many-to-many association

    - by Perry Hoekstra
    In Hibernate HQL, how would you query through a many-to-many association. If I have a Company with multiple ProductLines and other companies can offer these same product lines, I have a Company entity, a ProductLine entity and an association table CompanyProductLine. In SQL, I can get what I need like this: select * from company c where c.companyId in (select companyId from companyProductLine cpl, productline pl where cpl.productLineId = pl.productLineId and pl.name= 'some value'); My problem sees to lie with the association I defined in the Company.hbm.xml file: <set name="productLines" cascade="save-update" table="CompanyProductLine"> <key column="companyId"/> <many-to-many class="com.foo.ProductLine" column="productLineId" /> </set> Any HQL I seem to come up with will throw a: 'expecting 'elements' or 'indices"' Hibernate exception. Thoughts on what the proper HQL would be?

    Read the article

  • Any way to optimize this MySQL query?

    - by manyxcxi
    My table looks like this: `MyDB`.`Details` ( `id` bigint(20) NOT NULL, `run_id` int(11) NOT NULL, `element_name` varchar(255) NOT NULL, `value` text, `line_order` int(11) default NULL, `column_order` int(11) default NULL ); I have the following SELECT statement in a stored procedure SELECT RULE ,TITLE ,SUM(IF(t.PASSED='Y',1,0)) AS PASS ,SUM(IF(t.PASSED='N',1,0)) AS FAIL FROM ( SELECT a.line_order ,MAX(CASE WHEN a.element_name = 'PASSED' THEN a.`value` END) AS PASSED ,MAX(CASE WHEN a.element_name = 'RULE' THEN a.`value` END) AS RULE ,MAX(CASE WHEN a.element_name = 'TITLE' THEN a.`value` END) AS TITLE FROM Details a WHERE run_id = runId GROUP BY line_order ) t GROUP BY RULE, TITLE; *runId is an input parameter to the stored procedure. This query takes about 14 seconds to run. The table has 214856 rows, and the particular run_id I am filtering on has 162204 records. It's not on a super high power machine, but I feel like I could be doing this more efficiently. My main goal is to summarize by Rule and Title and show Pass and Fail count columns.

    Read the article

  • Android quotes within an sql query string

    - by miannelle
    I want to perform a query like the following: uvalue = EditText( some user value ); p_query = "select * from mytable where name_field = '" + uvalue + "'" ; mDb.rawQuery( p_query, null ); if the user enters a single quote in their input it crashes. If you change it to: p_query = "select * from mytable where name_field = \"" + uvalue + "\"" ; it crashes if the user enters a double quote in their input. and of course they could always enter both single and double quotes.

    Read the article

  • Multi join query returns to many results and improperly matched

    - by Woot4Moo
    I have the following minimal schema in Oracle: http://sqlfiddle.com/#!4/c1ed0/14 The queries I have run yield too many results and this query: select cat.*, status.*, source.* from cats cat, status status, source source Left OUTER JOIN source source2 on source2.sourceid = 1 Right OUTER JOIN status status2 on status2.isStray =0 order by cat.name will yield incorrect results. What I am expecting is a table that looks like the following however I cannot seem to come up with the correct SQL. NAME AGE LENGTH STATUSID CATSOURCE ISSTRAY SOURCEID CATID Adam 1 25 null null null 1 2 Bill 5 1 null null null null null Charles 7 5 null null null null null Steve 12 15 1 1 1 1 1 In plain English what I am looking for is to return all known cats + their associated cat source + their cat status while retaining null values. The only information I will have is the source that I am curious about. I also only want the cats that have a status of either STRAY or UNKNOWN (null)

    Read the article

  • SQL Query over three different tables

    - by choise
    i got three tables CATS id name ------------------------------ 1 category1 2 category2 3 category3 4 category4 PRODUCT id name ------------------------------ 1 product1 2 product2 ZW-CAT-PRODUCT id_cats id_product ------------------------------ 1 1 3 1 4 2 now i want to get my products and their categories product1 => category1,category3 product2 => category4 is there a way to get this array (or object or something) with one mysql query? i tried a bit with JOINS, but it seems thats this is not exactly what i need, or? currently i'm using 3 querys (i think thats too much). any suggestions?

    Read the article

  • 2 Select or 1 Join query ?

    - by xRobot
    I have 2 tables: book ( id, title, age ) ---- 100 milions of rows author ( id, book_id, name, born ) ---- 10 millions of rows Now, supposing I have a generic id of a book. I need to print this page: Title: mybook authors: Tom, Graham, Luis, Clarke, George So... what is the best way to do this ? 1) Simple join like this: Select book.title, author.name From book, author WHERE ( author.book_id = book.id ) AND ( book.id = 342 ) 2) For avoid the join, I could make 2 simple query: Select title FROM book WHERE id = 342 Select name FROM author WHERE book_id = 342 What is the most efficient way ?

    Read the article

  • How to do this query?

    - by Damiano
    Hello everybody! I have a mysql table with these columns: ID (auto-increment) ID_BOOK (int) PRICE (double) DATA (date) I know two ID_BOOK values, example, 1 and 2. QUERY: I have to extract all the PRICE (of the ID_BOOK=1 and ID_BOOK=2) where DATA is the same! Table example: 1 1 10.00 2010-05-16 2 1 11.00 2010-05-15 3 1 12.00 2010-05-14 4 2 18.00 2010-05-16 5 2 11.50 2010-05-15 Result example: 1 1 10.00 2010-05-16 4 2 18.00 2010-05-16 2 1 11.00 2010-05-15 5 2 11.50 2010-05-15 ID_BOOK=2 hasn't 2010-05-14 so i jump it. Thank you so much!

    Read the article

  • Mysql on duplicate key update + sub query

    - by jwzk
    Using the answer from this question: http://stackoverflow.com/questions/662877/need-mysql-insert-select-query-for-tables-with-millions-of-records new_table * date * record_id (pk) * data_field INSERT INTO new_table (date,record_id,data_field) SELECT date, record_id, data_field FROM old_table ON DUPLICATE KEY UPDATE date=old_table.data, data_field=old_table.data_field; I need this to work with a group by and join.. so to edit: INSERT INTO new_table (date,record_id,data_field,value) SELECT date, record_id, data_field, SUM(other_table.value) as value FROM old_table JOIN other_table USING(record_id) ON DUPLICATE KEY UPDATE date=old_table.data, data_field=old_table.data_field, value = value; I can't seem to get the value updated. If I specify old_table.value I get a not defined in field list error.

    Read the article

  • I need to simplify a MySQL sub query for performance - please help

    - by Richard
    I have the following query which is takin 3 seconds on a table of 1500 rows, does someone know how to simplify it? SELECT dealers.name, dealers.companyName, dealer_accounts.balance FROM dealers INNER JOIN dealer_accounts ON dealers.id = dealer_accounts.dealer_id WHERE dealer_accounts.id = ( SELECT id FROM dealer_accounts WHERE dealer_accounts.dealer_id = dealers.id AND dealer_accounts.date < '2010-03-30' ORDER BY dealer_accounts.date DESC, dealer_accounts.id DESC LIMIT 1 ) ORDER BY dealers.name I need the latest dealer_accounts record for each dealer by a certain date with the join on the dealer_id field on the dealer_accounts table. This really should be simple, I don't know why I am struggling to find something.

    Read the article

  • Mysql query help needed

    - by Me-and-Coding
    Hi, i have two tables category and hotels where category.id should be equal to hotels.catid. Now how do i select 3 rows from each different category from the hotels table. I have this query: select h.* from hotels h inner join category c on h.catid = c.id order by h.catid, h.hid this selects all records, but i want to select three rows per different category so in all it should return 9 rows with 3 rows for each category. If this can not be done in mysql, you could also suggest php code please. Thanks

    Read the article

  • Query to sum duplicated fields

    - by g0sha
    Here is mysql data id usr good quant delayed cart_ts ------------------------------------------------------ 14 4 1 1 0 20100601235348 13 4 11 1 0 20100601235345 12 4 4 1 0 20100601235335 11 4 1 1 0 20100601235051 10 4 11 1 0 20100601235051 9 4 4 1 0 20100601235051 15 4 2 1 0 20100601235350 16 4 7 1 0 20100602000537 17 4 3 1 0 20100602000610 18 4 3 1 0 20100602000616 19 4 8 1 0 20100602000802 20 4 8 1 0 20100602000806 21 4 8 1 0 20100602000828 22 4 8 1 0 20100602000828 23 4 8 1 0 20100602000828 24 4 8 1 0 20100602000828 25 4 8 1 0 20100602000828 26 4 8 1 0 20100602000829 27 4 8 1 0 20100602000829 28 4 9 1 0 20100602001045 29 4 10 1 0 20100602001046 I need to group fields in witch usr & good has duplicated values with summing quant field for getting smth like this: id usr good quant delayed cart_ts ------------------------------------------------------ 14 4 1 2 0 20100601235348 13 4 11 2 0 20100601235345 12 4 4 2 0 20100601235335 15 4 2 1 0 20100601235350 16 4 7 1 0 20100602000537 17 4 3 2 0 20100602000610 19 4 8 9 0 20100602000802 28 4 9 1 0 20100602001045 29 4 10 1 0 20100602001046 Which MySQL query I need to do to have this effect?

    Read the article

  • Query executes with no error but not in trigger

    - by liaqat ali
    I am facing a strange problem in creating trigger in MS SQL. I have a query that executes with out an error but when I place it within trigger body, it gives error Invalid column name 'ScreenName'. I am placing whole trigger code here. Please trace the issue. CREATE TRIGGER [dbo].[tr_tbFieldLabels_FieldLabelLength] ON [dbo].[tbFieldLabels] AFTER INSERT AS Update tbFieldLabels Set TextBoxLength = (SELECT top 1 TextboxLength FROM tbFieldLabelsSource FLS WHERE FLS.ScreenName = Inserted.ScreenName AND tbFieldLabelsSource.SystemName = Inserted.SystemName) FROM tbFieldLabels , Inserted WHERE tbFieldLabels.ID = Inserted.ID GO Please help me ASAP.

    Read the article

< Previous Page | 27 28 29 30 31 32 33 34 35 36 37 38  | Next Page >