将SQL Server查询转换为MySQL [英] Convert SQL Server query to MySQL

查看:87
本文介绍了将SQL Server查询转换为MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
为数字选择TOP X(或最低)百分比MySQL中的值

Possible Duplicate:
Select TOP X (or bottom) percent for numeric values in MySQL

我该如何在MySQL中编写此查询?

How would I write this query in MySQL??

SELECT TOP 50 PERCENT * FROM Persons

表中的条目数将不断变化,因此我需要按百分比而不是固定数进行选择.

The number of entries in the table will be constantly changing so I need to select by percentage rather than a fixed number.

推荐答案

这实际上是

This is actually a duplicate question, but I now have a better, single-pass, fast, answer:

SELECT *
FROM
(
    SELECT tbl.*, @counter := @counter +1 counter
    FROM (select @counter:=0) initvar, tbl
    ORDER BY ordcolumn
) X
WHERE counter <= (50/100 * @counter)
ORDER BY ordcolumn;

这篇关于将SQL Server查询转换为MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆