首页 \ 问答 \ 按逻辑顺序排序(sql order by logic)

按逻辑顺序排序(sql order by logic)

我有一个包含两列的表。 其中一列包含文本,另一列包含整数值。

我需要这个表按整数值排序(更高的值到顶部),但如果整数值等于0,那么我需要按字母顺序排序该行。 让我们说我有这张桌子

TextCol|IntCol|
-------|------|
Delta  |  0   |
Alpha  |  0   |
Beta   |  3   |
Sierra |  2   |
Gama   |  1   |

现在我需要这个:

TextCol|IntCol|
-------|------|
Beta   |  3   |
Sierra |  2   |
Gama   |  1   |
Alpha  |  0   |
Delta  |  0   |

这个SQL查询是什么?


I have a table that contains two columns. One of the columns contain text and the other contain integer values.

I need this table to be ordered by the integer value (higher values to the top) but if the integer value equals to 0 then I need that row to be ordered alphabetically aswell. Lets say that I have this table

TextCol|IntCol|
-------|------|
Delta  |  0   |
Alpha  |  0   |
Beta   |  3   |
Sierra |  2   |
Gama   |  1   |

Now I need this :

TextCol|IntCol|
-------|------|
Beta   |  3   |
Sierra |  2   |
Gama   |  1   |
Alpha  |  0   |
Delta  |  0   |

What would be the SQL query for this?


原文:https://stackoverflow.com/questions/39079181
更新时间:2022-12-20 06:12

最满意答案

有一个CUDA工具可以为您获得良好的网格和块大小: Cuda Occupancy API

响应“我选择更大的块大小,此代码执行得越快” - 不一定,因为您需要提供最大占用率的大小(活动warp与可能的活动warp总数的比率)。

有关其他信息,请参阅此答案如何为CUDA内核选择网格和块尺寸?

最后,对于支持Kelper或更高版本的Nvidia GPU,有一些改进的内在函数可以使缩减更容易,更快。 这是一篇关于如何使用shuffle内在函数的文章: 在开普勒上更快的并行缩减

选择线程数的更新:

如果导致寄存器使用效率降低,则可能不希望使用最大线程数。 从占用的链接:

为了计算占用率,每个线程使用的寄存器数量是关键因素之一。 例如,具有计算能力1.1的设备每个多处理器具有8,192个32位寄存器,并且最多可以驻留768个并发线程(每个warp 24个warp x 32个线程)。 这意味着在其中一个设备中,为了使多处理器具有100%的占用率,每个线程最多可以使用10个寄存器。 然而,这种确定寄存器计数如何影响占用的方法没有考虑寄存器分配粒度。 例如,在计算能力1.1的设备上,每个线程使用12个寄存器的128个线程块的内核导致每个多处理器有5个活动128线程块的占用率为83%,而具有256个线程块的内核每个线程使用相同的12个寄存器导致占用率为66%,因为只有两个256线程块可以驻留在多处理器上。

因此我理解它的方式是,由于可以分配寄存器的方式,增加的线程数可能会限制性能。 但是,情况并非总是如此,您需要自己进行计算(如上所述),以确定每个块的最佳线程数。


There is a CUDA tool to get good grid and block sizes for you : Cuda Occupancy API.

In response to "The bigger I choose blockSize, the faster this code will execute" -- Not necessarily, as you want the sizes which give max occupancy (the ratio of active warps to the total number of possible active warps).

See this answer for additional information How do I choose grid and block dimensions for CUDA kernels?.

Lastly, for Nvidia GPUs supporting Kelper or later, there are shuffle intrinsics to make reductions easier and faster. Here is an article on how to use the shuffle intrinsics : Faster Parallel Reductions on Kepler.

Update for choosing number of threads:

You might not want to use the maximum number of threads if it results in a less efficient use of the registers. From the link on occupancy :

For purposes of calculating occupancy, the number of registers used by each thread is one of the key factors. For example, devices with compute capability 1.1 have 8,192 32-bit registers per multiprocessor and can have a maximum of 768 simultaneous threads resident (24 warps x 32 threads per warp). This means that in one of these devices, for a multiprocessor to have 100% occupancy, each thread can use at most 10 registers. However, this approach of determining how register count affects occupancy does not take into account the register allocation granularity. For example, on a device of compute capability 1.1, a kernel with 128-thread blocks using 12 registers per thread results in an occupancy of 83% with 5 active 128-thread blocks per multi-processor, whereas a kernel with 256-thread blocks using the same 12 registers per thread results in an occupancy of 66% because only two 256-thread blocks can reside on a multiprocessor.

So the way I understand it is that an increased number of threads has the potential to limit performance because of the way the registers can be allocated. However, this is not always the case, and you need to do the calculation (as in the above statement) yourself to determine the optimal number of threads per block.

相关问答

更多
  • 并行缩减将首先添加元素对: 1 1+3 4+6 2 2+4 3 4 具有奇数个元素的示例通常会实现为: 1 1+4 5+3 8+7 2 2+5 7+0 3 3+0 4 0+0 5 0 0 0 也就是说,通常并行缩减将与2次幂线程一起使用,并且至多一个线程块(最后一个)将具有少于完整的数据补充。 处理此问题的常用方法是将数据填零到线程块大小。 如果你研究cuda 并行缩减示例代码,你会发现这个例子。 A parallel reduction will add pairs of ele ...
  • 有一个CUDA工具可以为您获得良好的网格和块大小: Cuda Occupancy API 。 响应“我选择更大的块大小,此代码执行得越快” - 不一定,因为您需要提供最大占用率的大小(活动warp与可能的活动warp总数的比率)。 有关其他信息,请参阅此答案如何为CUDA内核选择网格和块尺寸? 。 最后,对于支持Kelper或更高版本的Nvidia GPU,有一些改进的内在函数可以使缩减更容易,更快。 这是一篇关于如何使用shuffle内在函数的文章: 在开普勒上更快的并行缩减 。 选择线程数的更新: 如果 ...
  • 使用Thrust ,一个带有CUDA的STL灵感库。 有关如何执行缩减的示例,请参阅“ 快速入门指南” 。 Use Thrust, An STL inspired library that comes with CUDA. See the Quick Start Guide for examples on how to perform reductions.
  • 这里有几个问题。 您需要修改warp和block最小函数,以便在每次找到新的局部最小值时传播最小值及其索引。 也许是这样的: __inline__ __device__ void warpReduceMin(int& val, int& idx) { for (int offset = warpSize / 2; offset > 0; offset /= 2) { int tmpVal = __shfl_down(val, offset); int tmpIdx = ...
  • 如果我理解正确,您希望将Object1.lower.x减少为一个结果,将Object1.lower.y减少为另一个结果,依此类推。 对于任何给定的对象,有四个要减少的数组,所有长度都相等(对于对象)。 有许多可能的方法,一个影响因素是系统中的对象总数。 我会假设这个数字很大。 为获得最佳性能,您需要最佳的内存访问模式,并希望避免分歧。 由于全等数组的数量是4,如果你采用天真的做法,每个线程在下面做一个数组,你不仅会遭受糟糕的内存访问,而且h / w还需要检查每次迭代哪些线程在warp需要执行循环 - 那些不 ...
  • 什么阻止你做这样的事情: template __global__ void kernelSum(const T* __restrict__ input, T* __restrict__ per_block_results, const size_t lda, const size_t n) { extern __shared__ T sdata[]; // A ...
  • 您创建N线程。 第一个线程查看位置0,N,2 * N,...的值。第二个线程查看值1,N + 1,2 * N + 1,......这是第一个循环。 它将length值减少为N值。 然后每个线程将其最小值保存在共享/本地内存中。 然后你有一个同步指令( barrier(CLK_LOCAL_MEM_FENCE) 。)然后你有共享/本地内存的标准减少。 完成后,具有本地ID 0的线程将其结果保存在输出数组中。 总而言之,您将从length减少到N/get_local_size(0)值。 完成此代码执行后,您需要执 ...
  • 这是与MSVC和nvcc的已知不兼容性。 见这里的例子。 解决方案是定义您自己的double2版本并使用它。 仅供参考,我可以使用CUDA 5.5在Linux 64位盒上正确编译和运行代码。 This is a known incompatibility with MSVC and nvcc. See here for example. The solution is to define your own version of double2 and use that instead. Just for r ...
  • 您可以使用跨步范围方法 ,以及3次调用thrust :: minmax_element ,以在不修改数据存储的情况下获得所需的结果。 这是一个有效的例子: $ cat t491.cu #include #include #include #include #include #i ...
  • 减少是一种你可以用块做的操作。 最简单的解决方案是在GPU上分配两个数据缓冲区和两个结果缓冲区,然后通过执行缩减内核重叠传输到GPU。 当GPU忙时,您的CPU可以减少连续GPU减少的输出。 这样,您可以分摊大部分数据传输成本,并处理部分缩减结果。 您可以使用带有CUDA示例的标准缩减内核NVIDIA供应来完成所有这些工作。 Reduction is an operation which you can do in chunks. The simplest solution would be to allo ...

相关文章

更多

最新问答

更多
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • 电脑高中毕业学习去哪里培训
  • 电脑系统专业就业状况如何啊?
  • IEnumerable linq表达式(IEnumerable linq expressions)
  • 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
  • Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
  • 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
  • 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
  • 的?(The ? marks in emacs/haskell and ghc mode)
  • 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
  • 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
  • 悬停时的图像转换(Image transition on hover)
  • IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
  • 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
  • java分布式框架有哪些
  • Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
  • PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
  • 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
  • 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
  • typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
  • 武陟会计培训类的学校哪个好点?
  • 从链接中删除文本修饰(Remove text decoration from links)