这个问题有一段时间了,想知道是否有更快的查询。
我有一个表,每个 ID 包含多个条目,并且想要列出同一 ID 具有不同值的所有列。
| ID | 品牌 | 类型 |
|---|---|---|
| 1 | 本田 | 轿跑车 |
| 1 | 吉普车 | SUV |
| 2 | 福特 | 轿车 |
| 2 | 福特 | 交叉 |
上表示例:
行ID = 1具有不同的Brand和Type值,因此我希望每一列有一个结果行。
由于ID = 2只有一个品牌,但有多种类型,所以类型只有一个结果行。
想要的结果会是这样的。
| ID | 不同之处 |
|---|---|
| 1 | 品牌 |
| 1 | 类型 |
| 2 | 类型 |
我通过下面的查询解决了这个问题,用一个SELECT语句检查每一列,然后UNION全部完成:
SELECT ID, 'Brand' AS Discrepancy
FROM table
GROUP BY ID
HAVING COUNT(DISTINCT Brand) > 1
UNION
SELECT ID,'Type' AS Discrepancy
FROM table
GROUP BY ID
HAVING COUNT(DISTINCT Type) > 1; …Run Code Online (Sandbox Code Playgroud) 假设我想在循环中一遍又一遍地调用一些模板,并在模板参数中使用循环索引。像这样(除非不违法):
template <typename T, int k>
T function(T x) {
for (int i = 1; i <= k; ++i) {
for (int j = i - 1; j >= 0; --j) {
constexpr bool method_one_ok = function_of(i, j);
if (method_one_ok) {
x = method_one<T, i, j, k>(x);
} else {
x = method_two<T, i, j, k>(x);
}
}
}
return x;
}
Run Code Online (Sandbox Code Playgroud)
我知道如何使用递归模板和专业化来艰难地完成它,但这是我在 C++11 或更早版本中发现的恐怖之处。
有没有更干净的方法来做到这一点?
所以我试图对小数进行未经检查的转换(用作任何数字的“持有者”,可以是整数,可以是浮点数等)。C# 的问题是,在将小数转换为整数类型时,它不允许溢出,即使溢出是可以接受和预期的。未经检查的上下文仅适用于整数类型,不适用于小数,因此我正在寻找实现此目的的最佳方法。
这是我目前的方法(以Int32为例),如果您有任何建议,请写下来。
private static int ToInt32(decimal value)
{
if (value is < int.MinValue or > int.MaxValue)
{
decimal range = 1L + int.MaxValue - int.MinValue;
value = ((((value - int.MinValue) % range) + range) % range) + int.MinValue;
}
return (int)value;
}
Run Code Online (Sandbox Code Playgroud)
有了这个,如果我尝试转换2731498700m为 Int32,我会得到-1563468596(而不是 OverflowException),这正是我想要的。
将 Flutter 版本升级到后,3.19.0我在运行应用程序时收到此警告:
您正在使用 apply script 方法强制应用 Flutter 的 app_plugin_loader Gradle 插件,该方法已弃用并将在未来版本中删除。使用声明性插件块迁移到应用 Gradle 插件: https: //flutter.dev/go/flutter-gradle-plugin-apply
您正在使用 apply script 方法强制应用 Flutter 的主 Gradle 插件,该方法已弃用并将在未来版本中删除。使用声明性插件块迁移到应用 Gradle 插件: https: //flutter.dev/go/flutter-gradle-plugin-apply
如何删除这些已弃用的 gradle 设置。
标准(我使用的是 ISO C++17)中有详细记录ISO C++,整数除以 0 的结果是未定义的。这也可以从头中可用的预定义异常列表中排除零除异常看出<stdexcept>:
namespace std {
class logic_error;
class domain_error;
class invalid_argument;
class length_error;
class out_of_range;
class runtime_error;
class range_error;
class overflow_error;
class underflow_error;
}
Run Code Online (Sandbox Code Playgroud)
虽然我知道被调用函数只能检查除数是否为 0 并抛出domain_erroror overflow_error,但我想知道没有预定义零除异常的可能原因是什么。
我正在测试 Numba JIT 与 Python C 扩展的性能。对于基于 for 循环的函数来计算 2d 数组中所有元素的总和,C 扩展似乎比 Numba 等效项快 3-4 倍。
根据宝贵的意见,我意识到我应该编译(调用)一次 Numba JIT 的错误。我提供了修复后的测试结果以及额外的案例。但问题仍然是何时以及如何考虑哪种方法。
这是结果(time_s,值):
# 200 tests mean (including JIT compile inside the loop)
Pure Python: (0.09232537984848023, 29693825)
Numba: (0.003188209533691406, 29693825)
C Extension: (0.000905141830444336, 29693825.0)
# JIT once called before the test loop (to avoid compile time)
Normal: (0.0948486328125, 29685065)
Numba: (0.00031280517578125, 29685065)
C Extension: (0.0025129318237304688, 29685065.0)
# JIT no warm-up also no test loop (only calling once)
Normal: (0.10458517074584961, …Run Code Online (Sandbox Code Playgroud) 我正在开发用于屏幕录制的 JavaFX 项目。我需要录制整个屏幕。我使用依赖。monte-screen-recorder
这是我的pom.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.screenRecorder</groupId>
<artifactId>ScreenRecorder</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ScreenRecorder</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version>
</properties>
<dependencies>
<!-- JavaCV dependencies -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.jcodec</groupId>
<artifactId>jcodec-javase</artifactId>
<version>0.2.3</version>
</dependency>
<!-- JavaFX dependencies -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>17.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>17.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.stephenc.monte/monte-screen-recorder -->
<dependency>
<groupId>com.github.stephenc.monte</groupId>
<artifactId>monte-screen-recorder</artifactId>
<version>0.7.7.0</version>
</dependency>
<dependency>
<groupId>com.github.kokorin.jaffree</groupId>
<artifactId>jaffree</artifactId>
<version>2023.09.10</version>
</dependency>
</dependencies>
<build> …Run Code Online (Sandbox Code Playgroud) Run Code Online (Sandbox Code Playgroud)type Traversal' a b = forall f . Applicative f => (b -> f b) -> (a -> f a) type Lens' a b = forall f . Functor f => (b -> f b) -> (a -> f a)请注意,Lens' 和 Traversal' 之间的唯一区别是类型类约束。“镜头”具有函子约束,“遍历”具有应用约束。这意味着任何 Lens' 也自动成为有效的 Traversal'(因为 Functor 是 Applicative 的超类)。
我只是不遵循这里的逻辑顺序。我们知道每个Applicative都是一个Functor。由此看来,如果有的话,难道不应该得出每个Traversal'都是 a 吗Lens'?然而,本教程得出了相反的结论。
我发现内核代码中的一些宏定义展开前后是一样的。为什么要这么麻烦地定义这个宏呢?
例如,在/arch/arm64/include/asm/atomic.h中:
#define arch_atomic_add_return_relaxed arch_atomic_add_return_relaxed
#define arch_atomic_add_return_acquire arch_atomic_add_return_acquire
#define arch_atomic_add_return_release arch_atomic_add_return_release
#define arch_atomic_add_return arch_atomic_add_return
Run Code Online (Sandbox Code Playgroud) 如果您尝试使用 PHP PDO 连接到最新版本的 mariadb (11.3.2),您将看到此错误,并且客户端将无法连接:
SQLSTATE[HY000] [2054] Server sent charset (0) unknown to the client. Please, report to the developers
c ×2
c++ ×2
.net ×1
android ×1
applicative ×1
c# ×1
compilation ×1
deprecated ×1
flutter ×1
functor ×1
gradle ×1
haskell ×1
haskell-lens ×1
java ×1
javafx ×1
linux-kernel ×1
macros ×1
mariadb ×1
mysqlnd ×1
numba ×1
numpy ×1
pandas ×1
php ×1
postgresql ×1
python ×1
sql ×1
templates ×1