标签: where-clause

如何在MySQL Insert语句中添加where子句?

这不起作用:

INSERT INTO users (username, password) VALUES ("Jack","123") WHERE id='1';
Run Code Online (Sandbox Code Playgroud)

任何想法如何通过id缩小插入到特定行?

mysql insert where-clause

7
推荐指数
3
解决办法
9万
查看次数

在WHERE条件中获取SQL中的最后一条记录

我有loanTable两个字段loan_idstatus

loan_id status
==============
1       0
2       9
1       6
5       3
4       5
1       4  <-- How do I select this??
4       6
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我需要显示在过去Statusloan_id1点即是status4.可以帮助我在此查询.

sql t-sql sql-server where-clause

7
推荐指数
2
解决办法
4万
查看次数

Mysql Where ... In ... AND where ... in ...应该只匹配相同的索引

我有查询:

SELECT * FROM `users` 
WHERE (`firstname` LIKE 'Luke' AND `lastname` LIKE 'Skywalker') OR  
 (`firstname` LIKE 'Foo' AND `lastname` LIKE 'Bar') OR 
(`firstname` LIKE 'Tom' AND `lastname` LIKE 'Turner');
Run Code Online (Sandbox Code Playgroud)

但我想通过使用where ... in ...来尝试使其更具可读性

SELECT * FROM users 
WHERE `firstname` 
    IN ('Luke','Foo','Tom') AND `lastname` IN ('Skywalker','Bar','Turner');
Run Code Online (Sandbox Code Playgroud)

但不幸的是,这也将匹配"Tom Skywalker","Foo Turner"所有混合你可以想到.

我必须选择first和lastname(也许更多字段,如DOB),因为我从外部API获取数据,我必须检查这些名称是否在我们的系统中.

mysql where-clause

7
推荐指数
1
解决办法
659
查看次数

JasperReports中的条件Where子句

假设我想要一个JasperReport,让用户可以根据需要过滤日期.SQL如下:

select * from foo where bar = $P{bar} and some_date > $P{some.date}
Run Code Online (Sandbox Code Playgroud)

现在,如果他们没有通过日期,我不想按某个日期过滤.我发现以下人们使用的kludge:

select * from foo where bar = $P{bar} $P!{some.date.fragment}
Run Code Online (Sandbox Code Playgroud)

并且some.date.fragment参数使用以下默认值定义:

($P{some.date} == null || $P{some.date}.equals("")) ? "" : "AND some_date >'" + new java.sql.Date($P{some.date}.getTime()).toString() + "'"
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为toString不以我的SQL服务器理解的格式输出日期.我想条件仍然使用jdbc驱动程序的预准备语句并输入参数,我只是希望准备好的语句依赖于参数是否为null.可以这样做吗?

sql jasper-reports where-clause

7
推荐指数
1
解决办法
8282
查看次数

当'有'时,为什么你有'哪里'?

我知道这个问题已经讨论得很多了,但是我的研究都没有让我相信MySQL中的' where'和' having'条款之间的区别.根据我的理解,我们可以使用' having' 来实现'where'子句可以完成的所有事情.例如.select * from users having username='admin'.那为什么你需要' where'条款?使用哪里可以产生任何性能差异?

mysql sql where where-clause having-clause

7
推荐指数
1
解决办法
457
查看次数

如何在 Postgres 中使用 WHERE 子句添加索引

我想WHERE在 Postgres 中添加一个带有子句的索引。我使用以下查询来执行此操作:

create index concurrently em_openorder_idx on line (m_product_id, org_id, date) where date >= now() - 90
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

functions in index predicate must be marked IMMUTABLE
Run Code Online (Sandbox Code Playgroud)

postgresql indexing where-clause

6
推荐指数
2
解决办法
1万
查看次数

如何将值从文件加载到mysql,在(文件)中

我需要选择 id 所在的位置(这里我想加载文本文件,每行一个 int 值)

任何帮助,将不胜感激

mysql file where-clause

6
推荐指数
1
解决办法
3795
查看次数

在 PySpark 中对多个单词使用 LIKE 运算符

我有一个 DataFrame dfPySpark如下所示 -

\n\n
+-----+--------------------+-------+\n|   ID|           customers|country|\n+-----+--------------------+-------+\n|56   |xyz Limited         |U.K.   |\n|66   |ABC  Limited        |U.K.   |\n|16   |Sons & Sons         |U.K.   |\n|51   |T\xc3\x9cV GmbH            |Germany|\n|23   |Mueller GmbH        |Germany|\n|97   |Schneider AG        |Germany|\n|69   |Sahm UG             |Austria|\n+-----+--------------------+-------+\n
Run Code Online (Sandbox Code Playgroud)\n\n

我只想保留ID从 5 或 6 开始的那些行。所以,我希望我的最终数据框看起来像这样 -

\n\n
+-----+--------------------+-------+\n|   ID|           customers|country|\n+-----+--------------------+-------+\n|56   |xyz Limited         |U.K.   |\n|66   |ABC  Limited        |U.K.   |\n|51   |T\xc3\x9cV GmbH            |Germany|\n|69   |Sahm UG             |Austria|\n+-----+--------------------+-------+\n
Run Code Online (Sandbox Code Playgroud)\n\n

这可以通过多种方式实现,而且这不是问题。但是,我有兴趣了解如何使用语句来完成此操作LIKE

\n\n

如果我只对从 5 开始的那些行感兴趣ID,就可以像这样轻松完成 -

\n\n
df=df.where("ID like (\'5%\')")\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的问题: …

where-clause dataframe sql-like pyspark

6
推荐指数
2
解决办法
2万
查看次数

Numpy where 可广播条件

numpy.where()现在已经使用过很多次了,我总是想知道文档中的以下声明:

x、y 和条件需要可广播为某种形状。

我明白为什么这对于xy都是必要的。我们想要将这两个数组组合起来,因此它们应该可以广播为相同的形状。然而,我不明白为什么这对于这种情况也如此重要。这只是决策规则。假设我有以下三种形状:

condition = (100,)
x         = (100, 5)
y         = (100, 5)
result    = np.where(condition, x, y)
Run Code Online (Sandbox Code Playgroud)

这会导致 ValueError,因为“操作数无法一起广播”。据我了解,这个表达式应该可以正常工作,因为我编写了可广播的 x 和 y 的结果。

您能帮我理解为什么条件与 x 和 y 一起广播如此重要吗?

python numpy where-clause

6
推荐指数
1
解决办法
430
查看次数

朱莉娅中的关键字“where”是什么意思?

struct A{T<:myType}
    arg::T
    arg1
    function A{T}(arg,arg1) where {T}
        
        return new{T}(arg,arg1)
    end
end
Run Code Online (Sandbox Code Playgroud)

我的问题是,为什么我应该在内部构造函数旁边添加where {T} 。没有它我得到:T 未定义

constructor struct where-clause julia

6
推荐指数
2
解决办法
4794
查看次数