where

R, issue with sqldf: cannot make condition on date

隐身守侯 提交于 2019-12-25 04:48:08
问题 I have a R dataframe with a field date (type date), i want to query this dataframe using sqldf library, but the where condition doesn't seem to work on the date field. The query I'm using is: sqldf("select * from elog where date >= '1997-01-01' limit 6") It returns me an empty dataframe even though 'elog' has lines having 1997-01-01 as date 回答1: You could try the same command after loading library(RH2) library(RH2) library(sqldf) sqldf("select * from elog where date >= '1997-01-01' limit 6")

Select Distinct Field on Join in MySQL

↘锁芯ラ 提交于 2019-12-25 04:47:04
问题 I am joining two large tables in MySQL based on a unique identifier they both share. Because there are a large number of fields, I do not want to list out all fields after SELECT. Instead I want to select all fields, but I do not want recurring fields (the shared unique identifier in this case) to be repeated. With this example query: SELECT * FROM Gr3_PracMath_Jan11_D1 as a, student_list_011811 as b WHERE a.StudentID = b.StudentID The field StudentID is repeated. Is there a way to prevent

Oracle invalid number in clause

不羁的心 提交于 2019-12-24 17:08:26
问题 I'm struggling with getting a query to work, and I could really use some help. We have an in house app that we use for building small web apps where I work. It's basically a drag and drop GUI. There's functionality built in to access query string values using the key. I'm passing a comma separated list of values into a page through the query string. I'm then trying to use the list of values as part of an in clause in a query. I can see that the value is correct in the query string. orders=1,2

Extra Long Where/In Statement - Better option?

 ̄綄美尐妖づ 提交于 2019-12-24 13:34:10
问题 I've got about 13,000 AccountIDs that I need to pull various data from several data tables using left-joins. The total # of accountIDs is in the millions. I don't have write-access to the server but I was wondering if there was a way I could maybe create a custom/temporary table anyway and do a join to that rather than writing a really, really long Where AccountID in (.....) statement. The accountIDs are currently in a single Excel column so I'd have to get them back in the server somehow.

C# Entity Framework select max after where filter of not nullable field

北慕城南 提交于 2019-12-24 00:47:31
问题 I have a not nullable field ( Num ) class MyTable { //... public int Num { get; set; } public string Category { get; set; } //... } want to find maximum Num for Category == "A" var maxnum = myTable .Where(r => r.Category == "A") .Max(r => r.Num); the problem occurred when there wasn't any record of category == "A" . Because the result of Where() is null so the result of Max() will be null but when Num is not nullable the exception occurred. I can fix it by setting Num as nullable in table

SQL isset and not showing blank 'cells'

限于喜欢 提交于 2019-12-23 19:30:52
问题 I'm using one of my MySQL database tables as an actual table, with times of the day as each column, and one column called day. You guessed it, in day it says the day of the week, and in the rest of the cells it says what is happening at that time. What I want to do is only show the cells that have value in it. In my case, I'm always going to have all the rows and 2 columns full. The 2 columns are 'day' and '19:00', however in the future I might add values for '18:00' etc. So, how can I only

Conditional where statement in T-SQL

不羁的心 提交于 2019-12-23 12:06:09
问题 I've got a table that returns the history of a value, as well as the current one, each with a date. The oldest date is the main record. If the value is changed, a new record is created, with the old value, and the main record is updated with the new value. If this happens again, a third record is created, which contains the now old value. So if the value starts at 4, changes to 2, then again changes to 1. The records will go 1 4 2 I'm currently creating an inner join on the table to itself as

Using Case Statement in SQL with parameter/variable to check for Null values

假如想象 提交于 2019-12-23 10:20:02
问题 I am trying to write a SQL Select statement to return records based on a user input through a front end. I want to write the Select statement like this: SELECT somefields FROM sometable WHERE CASE variable WHEN 'blank' THEN field IS NULL ELSE field = field END Basically I either want to filter a column to find NULL values or ignore the filter and return all values depending on the value of the variable. I know that the results of the CASE statement is not executable but how can I do this? 回答1

How to use same list twice in WHERE clause?

梦想的初衷 提交于 2019-12-23 09:47:27
问题 My SQL query contains a WHERE clause looking like this: WHERE name1 in ('Emily', 'Jack', 'James', 'Chloe') OR name2 in ('Emily', 'Jack', 'James', 'Chloe') Note that the same list appears twice, which is quite unsatisfying (and my real list is actually longer). What would be a better way to write this query? 回答1: You can use arrays and overlap operator &&, e.g.: with my_table(name1, name2) as ( values ('Emily', 'Bob'), ('Ben', 'Jack'), ('Bob', 'Ben') ) select * from my_table where array[name1,

Laravel Eloquent orWhere Query

牧云@^-^@ 提交于 2019-12-23 08:07:46
问题 Can someone show me how to write this query in Eloquent? SELECT * FROM `projects` WHERE `id`='17' OR `id`='19' I am thinking Project::where('id','=','17') ->orWhere('id','=','19') ->get(); Also my variables (17 and 19) in this case are coming from a multi select box, so basically in an array. Any clues on how to cycle through that and add these where/orWhere clauses dynamically? Thanks. 回答1: You could do in three ways. Assume you've an array in the form ['myselect' => [11, 15, 17, 19],