Search Results

Search found 1421 results on 57 pages for 'distinct'.

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

  • How to fetch distinct values in Core Data?

    - by Andy
    So in looking through Core Data Snippets, I found the following code: ... [request setEntity:entity]; [request setResultType:NSDictionaryResultType]; [request setReturnsDistinctValues:YES]; [request setPropertiesToFetch:[NSArray arrayWithObject:@"<#Attribute name#>"]]; // Execute the fetch NSError *error; id requestedValue = nil; // WTF? This isn't defined or used anywhere NSArray *objects = [managedObjectContext executeFetchRequest:request error:&error]; if (objects == nil) { // handle the error } This is great and seems perfect for what I need...but how does one actually use it? I assume since it's returning dictionaries, I need a key to get at the values - but where's the key defined? Is that the "id requestedValue = nil" line? If so, how does "requestedValue" become the key? Xcode gives me a compiler warning about an unused variable at the "requestedValue" declaration. I feel like I'm missing something here. Thanks in advance for any assistance you can offer.

    Read the article

  • Django select distinct sum

    - by yoshi
    I have the following (greatly simplified) table structure: Order: order_number = CharField order_invoice_number = CharField order_invoice_value = CharField An invoice number can be identical on more than one order (order O1 has invoice number I1, order O2 has invoice number I1, etc.). All the orders with the same invoice number have the same invoice value. For example: Order no. Invoice no. Value O1 I1 200 O2 I1 200 O3 I1 200 04 I2 50 05 I2 100 What I am trying to do is do a sum over all the invoice values, but don't add the invoices with the same number more than once. The sum for the above items would be: 200+50+100. I tried doing this using s = orders.values('order_invoice_id').annotate(total=Sum('order_invoice_value')).order_by() and s = orders.values('order_invoice_id').order_by().annotate(total=Sum('order_invoice_value')) but I didn't get the desired result. I tried a few different solutions from similar questions around here but I couldn't get the desired result. I can't figure out what I'm doing wrong and what I actually should do to get a sum that uses each invoice value just once.

    Read the article

  • Select a distinct record, filtering is not working..

    - by help_inmssql
    Hello EVery I am new to SQl. query to result in the following records. I have a table with records as c1 c2 c3 c4 c5 c6 1 John 2.3.2010 12:09:54 4 7 99 2 mike 2.3.2010 13:09:59 8 6 88 3 ahmad 2.3.2010 13:09:59 1 9 19 4 Jim 23.3.2010 16:35:14 4 5 99 5 run 23.3.2010 12:09:54 3 8 12 I want to fecth only records. i.e only 1 latest record per day. If both of them happen at the same time, sort by C1.so in 1&3 it should fetch 3. 3 ahmad 2.3.2010 14:09:59 1 9 19 4 Jim 23.3.2010 16:35:14 4 5 99 I have got a new problem in this. If i filter the records based on conditions the last record is missing. I tried many ways but still it is failing. Here update_log is my table. SELECT * FROM update_log t1 WHERE (t1.c3) = ( SELECT MAX(t2.c3) FROM update_log t2 WHERE DATEDIFF(dd,t2.c3, t1.c3) = 0 ) and t1.c3 > '02.03.2010' and t1.modified_at <= '22.03.2010' ORDER BY t1.c3 ASC. But i am not able to retrieve the record 4 Jim 23.3.2010 16:35:14 4 5 99 I dont know this query results in only 3 ahmad 2.3.2010 14:09:59 1 9 19 The format of the column c3 is datetime. I am pumping the data into the column as using $date = date("d.m.Y H:i",time()); -- simple date fetch of today. Another query that i tried for the same purpose. select * from (select convert(varchar(10), c3,104) as date, max(c3) as max_date, max(c1) as Nr from update_log group by convert(varchar(10), c3,104)) as t2 inner join update_log as t1 on (t2.max_date = t1.c3 and convert(varchar(10), c3,104) = date and t1.[c1]= Nr) WHERE t1.c3 >= '02.03.2010' and t1.c3 <= '16.04.2010' . I even tried this way..the same error last record is not coming..

    Read the article

  • mysql count, distinct, join? COnfusion

    - by calum
    hello i have 2 tables: tblItems ID | orderID | productID 1 1 2 2 1 2 3 2 1 4 3 2 tblProducts productID | productName 1 ABC 2 DEF im attempting to find the most popular Product based on whats in "tblItems", and display the product Name and the number of times it appears in the tblItems table. i can get mysql to count up the total like: $sql="SELECT COUNT(productID) AS CountProductID FROM tblItems"; but i can't figure out how to join the products table on..if i try LEFT JOIN the query goes horribly wrong hopefully thats not too confusing..thankss

    Read the article

  • SQL Server Distinct Question

    - by RPS
    I need to be able to select only the first row for each name that has the greatest value. I have a table with the following: id name value 0 JOHN 123 1 STEVE 125 2 JOHN 127 3 JOHN 126 So I am looking to return: id name value 1 STEVE 125 2 JOHN 127 Any idea on the MSSQL Syntax on how to perform this operation?

    Read the article

  • Non distinct Unique ID in MySQL database table.

    - by Geoff
    First of, a simplified version: I am wondering if I can create a trigger to activate during INSERT (it's actually LOAD DATA INFILE) and NOT enter records for an RMA already in my table? I have a table that has no records that are unique. Some may be duplicates but there is one field that I can use to know if the data has been entered or not. For instance RMA Op Days --------------------- 213 Repair 0.10 213 Test 0.20 213 Repair 0.10 So I could do an index on the three columns together but as you see it's possible for an RMA to be in a step for the same amount of time twice so it's possible to have duplicate records. This data comes from a report that I cannot edit and this is all it provides. The key is that an RMA's data is only in the report once so if my database already has that RMA in it's records I want to skip the loading of that RMA's records from the report. By all means please let me know if that didn't make sense, I'll Explain as needed. I'm sure it's not uncommon but I couldn't find anything on the net.

    Read the article

  • Distinct rand() sequences yielding the same results in an expression

    - by suszterpatt
    Ok, this is a really weird one. I have an MPI program, where each process has to generate random numbers in a fixed range (the range is read from file). What happens is that even though I seed each process with a different value, and the numbers generated by rand() are different in each process, the expression to generate the random numbers still yields the same sequence between them. Here's all relevant code: // 'rank' will be unique for each process int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); // seed the RNG with a different value for each process srand(time(NULL) + rank); // print some random numbers to see if we get a unique sequence in each process // 'log' is a uniquely named file, each process has its own log << rand() << " " << rand() << " " << rand() << std::endl; // do boring deterministic stuff while (true) { // waitTimeMin and waitTimeMax are integers, Max is always greater than Min waitSecs = waitTimeMin + rand() % (waitTimeMax - waitTimeMin); log << "waiting " << waitSecs << " seconds" << std::endl; sleep(waitSecs); // do more boring deterministic stuff } Here's the output of each process, with 3 processes generating numbers in the range [1,9]. process 1: 15190 28284 3149 waiting 6 seconds waiting 8 seconds waiting 9 seconds waiting 4 seconds process 2: 286 6264 3153 waiting 6 seconds waiting 8 seconds waiting 9 seconds waiting 4 seconds process 3: 18151 17013 3156 waiting 6 seconds waiting 8 seconds waiting 9 seconds waiting 4 seconds So while rand() clearly generates different numbers, the expression to calculate waitSecs still evaluates to the same sequence on all processes. What's even weirder: if I run the program with the same parameteres again, only the first 3 random numbers will change, the rest of the "random" sequence will be exactly the same in each run! Changing the range of numbers will obviously produce a different result from this one, but the same parameters always yield the same sequence, between processes and between executions: except for the first 3 numbers. Just what the hell is going on here?

    Read the article

  • Index on column with only 2 distinct values

    - by Will
    I am wondering about the performance of this index: I have an "Invalid" varchar(1) column that has 2 values: NULL or 'Y' I have an index on (invalid), as well as (invalid, last_validated) Last_validated is a datetime (this is used for a unrelated SELECT query) I am flagging a small amount of items (1-5%) of rows in the table with this as 'to be deleted'. This is so when i DELETE FROM items WHERE invalid='Y' it does not perform a full table scan for the invalid items. A problem seems to be, the actual DELETE is quite slow now, possibly because all the indexes are being removed as they are deleted. Would a bitmap index provide better performance for this? or perhaps no index at all?

    Read the article

  • how to retrieve distinct values from multiple columns

    - by ANIL MANE
    Hello Experts, I have a flat text file data which I import into MSSQL table. It creates and table with specified name along with multiple columns as per data file. now I need a query which will return the data and its count. e.g. data file : BREAD,MILK BREAD,DIAPER,BEER,EGGS MILK,DIAPER,BEER,COKE BREAD,MILK,DIAPER,BEER BREAD,MILK,DIAPER,COKE BREAD,ICE,MANGO JUICE,BURGER Result should be BREAD | 5 MILK | 4 DIAPER| 4 and so on.

    Read the article

  • sql statement supposed to have 2 distinct rows, but only 1 is returned

    - by jello
    I have an sql statement that is supposed to return 2 rows. the first with psychological_id = 1, and the second, psychological_id = 2. here is the sql statement select * from psychological where patient_id = 12 and symptom = 'delire'; But with this code, with which I populate an array list with what is supposed to be 2 different rows, two rows exist, but with the same values: the second row. OneSymptomClass oneSymp = new OneSymptomClass(); ArrayList oneSympAll = new ArrayList(); string connStrArrayList = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\PatientMonitoringDatabase.mdf; " + "Initial Catalog=PatientMonitoringDatabase; " + "Integrated Security=True"; string queryStrArrayList = "select * from psychological where patient_id = " + patientID.patient_id + " and symptom = '" + SymptomComboBoxes[tag].SelectedItem + "';"; using (var conn = new SqlConnection(connStrArrayList)) using (var cmd = new SqlCommand(queryStrArrayList, conn)) { conn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { oneSymp.psychological_id = Convert.ToInt32(rdr["psychological_id"]); oneSymp.patient_history_date_psy = (DateTime)rdr["patient_history_date_psy"]; oneSymp.strength = Convert.ToInt32(rdr["strength"]); oneSymp.psy_start_date = (DateTime)rdr["psy_start_date"]; oneSymp.psy_end_date = (DateTime)rdr["psy_end_date"]; oneSympAll.Add(oneSymp); } } conn.Close(); } OneSymptomClass testSymp = oneSympAll[0] as OneSymptomClass; MessageBox.Show(testSymp.psychological_id.ToString()); the message box outputs "2", while it's supposed to output "1". anyone got an idea what's going on?

    Read the article

  • Call a javascript function at distinct time intervals

    - by Dkong
    I've created a stock ticker function and need to call it every 2 minutes. I've succeeded in doing this with the javascript setInterval function, but the problem is on the first call it waits 2 minutes before calling the function, whereas I want the first load to be called right away. function CallFunction() { setInterval("GetFeed()", 2000); }

    Read the article

  • Using a password to generate two distinct hashes without reducing password security

    - by Nevins
    Hi there, I'm in the process of designing a web application that will require the storage of GPG keys in an encrypted format in a database. I'm planning on storing the user's password in a bCrypt hash in the database. What I would like to be able to do is to use that bCrypt to authenticate the user then use the combination of the stored bCrypt hash and another hash of the password to encrypt and decrypt the GPG keys. My question is whether I can do this without reducing the security of the password? I was thinking I may be able to use something like an HMAC-SHA256 of a static string using the password and a salt as the secret key. Is there a better way to do this that I haven't thought of? Thanks

    Read the article

  • Permutations distinct under given symmetry (Mathematica 8 group theory)

    - by Yaroslav Bulatov
    Given a list of integers like {2,1,1,0} I'd like to list all permutations of that list that are not equivalent under given group. For instance, using symmetry of the square, the result would be {{2, 1, 1, 0}, {2, 1, 0, 1}}. Approach below (Mathematica 8) generates all permutations, then weeds out the equivalent ones. I can't use it because I can't afford to generate all permutations, is there a more efficient way? Update: actually, the bottleneck is in DeleteCases. The following list {2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0} has about a million permutations and takes 0.1 seconds to compute. Apparently there are supposed to be 1292 orderings after removing symmetries, but my approach doesn't finish in 10 minutes removeEquivalent[{}] := {}; removeEquivalent[list_] := ( Sow[First[list]]; equivalents = Permute[First[list], #] & /@ GroupElements[group]; DeleteCases[list, Alternatives @@ equivalents] ); nonequivalentPermutations[list_] := ( reaped = Reap@FixedPoint[removeEquivalent, Permutations@list]; reaped[[2, 1]] ); group = DihedralGroup[4]; nonequivalentPermutations[{2, 1, 1, 0}]

    Read the article

  • SQL query to select distinct record with 2 or more repetition in another field

    - by kyohiros
    So I have this table of book orders, it contains 2 columns, one is the order ID(primary key) and another is the ID of the book that the customer ordered. For example: | OrderID | BookID | | 0001 | B002 | | 0002 | B005 | | 0003 | B002 | | 0004 | B003 | | 0005 | B005 | | 0006 | B002 | | 0007 | B002 | What I want is to get the IDs of the books that got 2 or more purchases/orders, for example if I run the SQL query against the above data, I would get this as the result: | BookID | | B002 | | B005 | I don't know if this can be archived in SQL or I have to built a simpler statement and repetitive run the query against all the records in another language. I need some help and thanks for reading my question.

    Read the article

  • Counting distinct and duplicate attribute values in an array

    - by keruilin
    I have an array of users that's sorted in descending order based on total_points. I need to find the rank of each user in that array. The issue is that more than one user can have the same total points and, thus, the same rank. For example, three users could be in 3rd place with 200 Points. Here's my current code: class Leader < ActiveRecord::Base def self.points_leaders all_leaders = all_points_leaders # returns array of users sorted by total_points in desc order all_leaders_with_rank = [] all_leaders.each do |user| rank = all_leaders.index(user)+1 all_leaders_with_rank << Ldr.new(rank, user) # Ldr is a Struct end return all_leaders_with_rank end end How must I modify the code so that the correct rank is returned, and not just the value of the index position?

    Read the article

  • Groupby distinct how can I do that?

    - by Christophe Debove
    Hello, <?xml version="1.0"?> <Products> <product> <productId >1</productId> <textdate>11/11/2011</textdate> <price>200</price> </product> <product> <productId >6</productId> <textdate>11/11/2011</textdate> <price>100</price> </product> <product> <productId >1</productId> <textdate>16/11/2011</textdate> <price>290</price> </product> </Products> I've this xml and I want an xslt transformation that regroup product something like this : { product 1 : 11/11/2011 - 200 16/11/2011 - 290 } { product 6 11/11/2011 - 100 } I work with xslt 1.0 Asp .net C# XslCompiledTransformation

    Read the article

  • XPath to compare two distinct attributes of two elements

    - by user364902
    Suppose I have this XML: <x> <e s="1" t="A"/> <e s="2" t="A"/> <e s="1" t="B"/> </x> Is there any way to write an xpath to find any nodes named "e" which have the same value of @s as another node but a different value of @t for the same node. The first part is easy: //e[@s = //e/@s] as is the second part: //e[@t != //e[@t]] But I don't see any way to construct an xpath that compares two different attributes for two separate elements "e". Is there a way within the xpath syntax, or is it hopeless?

    Read the article

  • C++ function for picking from a list where each element has a distinct probability

    - by Stuart
    I have an array of structs and one of the fields in the struct is a float. I want to pick one of the structs where the probability of picking it is relative to the value of the float. ie struct s{ float probability; ... } sArray s[50]; What is the fastest way to decide which s to pick? Is there a function for this? If I knew the sum of all the probability fields (Note it will not be 1), then could I iterate through each s and compare probability/total_probability with a random number, changing the random number for each s? ie if( (float) (rand() / RAND_MAX) < probability)...

    Read the article

  • GROUP BY and SUM distinct date across 2 tables

    - by kenitech
    I'm not sure if this is possible in one mysql query so I might just combine the results via php. I have 2 tables: 'users' and 'billing' I'm trying to group summed activity for every date that is available in these two tables. 'users' is not historical data but 'billing' contains a record for each transaction. In this example I am showing a user's status which I'd like to sum for created date and deposit amounts that I would also like to sum by created date. I realize there is a bit of a disconnect between the data but I'd like to some all of it together and display it as seen below. This will show me an overview of all of the users by when they were created and what the current statuses are next to total transactions. I've tried UNION as well as LEFT JOIN but I can't seem to get either to work. Union example is pretty close but doesn't combine the dates into one row. ( SELECT created, SUM(status) as totalActive, NULL as totalDeposit FROM users GROUP BY created ) UNION ( SELECT created, NULL as totalActive, SUM(transactionAmount) as totalDeposit FROM billing GROUP BY created ) I've also tried using a date lookup table and joining on the dates but the SUM values are being added multiple times. note: I don't care about the userIds at all but have it in here for the example. users table (where status of '1' denotes "active") (one record for each user) created | userId | status 2010-03-01 | 10 | 0 2010-03-01 | 11 | 1 2010-03-01 | 12 | 1 2010-03-10 | 13 | 0 2010-03-12 | 14 | 1 2010-03-12 | 15 | 1 2010-03-13 | 16 | 0 2010-03-15 | 17 | 1 billing table (record created for every instance of a billing "transaction" created | userId | transactionAmount 2010-03-01 | 10 | 50 2010-03-01 | 18 | 50 2010-03-01 | 19 | 100 2010-03-10 | 89 | 55 2010-03-15 | 16 | 50 2010-03-15 | 12 | 90 2010-03-22 | 99 | 150 desired result: created | sumStatusActive | sumStatusInactive | sumTransactions 2010-03-01 | 2 | 1 | 200 2010-03-10 | 0 | 1 | 55 2010-03-12 | 2 | 0 | 0 2010-03-13 | 0 | 0 | 0 2010-03-15 | 1 | 0 | 140 2010-03-22 | 0 | 0 | 150 Table dump: CREATE TABLE IF NOT EXISTS `users` ( `created` date NOT NULL, `userId` int(11) NOT NULL, `status` smallint(6) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `users` (`created`, `userId`, `status`) VALUES ('2010-03-01', 10, 0), ('2010-03-01', 11, 1), ('2010-03-01', 12, 1), ('2010-03-10', 13, 0), ('2010-03-12', 14, 1), ('2010-03-12', 15, 1), ('2010-03-13', 16, 0), ('2010-03-15', 17, 1); CREATE TABLE IF NOT EXISTS `billing` ( `created` date NOT NULL, `userId` int(11) NOT NULL, `transactionAmount` int(11) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `billing` (`created`, `userId`, `transactionAmount`) VALUES ('2010-03-01', 10, 50), ('2010-03-01', 18, 50), ('2010-03-01', 19, 100), ('2010-03-10', 89, 55), ('2010-03-15', 16, 50), ('2010-03-15', 12, 90), ('2010-03-22', 99, 150);

    Read the article

  • Elegant way to distinct Path or Entry key

    - by sum1stolemyname
    I have an application loading CAD data (Custom format), either from the local filesystem specifing an absolute path to a drawing or from a database. Database access is realized through a library function taking the drawings identifier as a parameter. the identifiers have a format like ABC 01234T56-T, while my paths a typical windows Paths (eg x:\Data\cadfiles\cadfile001.bin). I would like to write a wrapper function Taking a String as an argument which can be either a path or an identifier which calls the appropriate functions to load my data. Like this: Function CadLoader(nameOrPath : String):TCadData; My Question: How can I elegantly decide wether my string is an idnetifier or a Path to a file? Use A regexp? Or just search for '\' and ':', which are not appearing in the Identifiers?

    Read the article

  • How to generate distinct random numbers per distinct threads in .NET?

    - by mark
    Dear ladies and sirs. I have to generate 19 bit random numbers. However, there is a constraint - two threads may not generate the same random number when running certain code. The simplest solution is lock the entire code. However, I would like to know if there is a non locking solution. I thought, I can incorporate ManagedThreadId within the produced random numbers, but the ManagedThreadId documentation on the Internet mentions that it may span the whole Int32 range. Unmanaged thread id seems to be limited to 11 bits, still this leaves me with just 8 truly random bits. Are there any other ways? Somehow to utilize the Thread Local Storage, may be? Thanks.

    Read the article

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