(SQL)如何获取队列中的条目数?

时间:2018-05-27 16:10:20

标签: mysql

我有这张桌子:

CREATE TABLE tickets (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
topic VARCHAR(64) NOT NULL,
priority TINYINT NOT NULL default 1,
created DATETIME); 

INSERT INTO tickets (id, topic, priority, created) VALUES
(1, 'kin23oi5n2', 3, '2018-05-27 16:00:54'),
(2, 'ewbrv32b3', 2, '2018-05-27 16:00:54'),
(3, 'aern23523', 1, '2018-05-27 16:01:15'),
(4, '4bt43t3', 5, '2018-05-27 16:01:15'),
(5, '32n523n5235n235t3n4', 4, '2018-05-27 16:01:39'),
(6, 'e2nr2n23n5235n23n523', 3, '2018-05-27 16:01:39');

我正在运行查询:

SELECT * FROM `tickets` order by `priority` ASC, `created` desc;

如何使用sql在此结果中获取id为5的行号?

更新

SELECT count(*) as pos FROM {门票{1}} 结果,我们获得WHERE ...; 我试着让我的结果与此类似,但包含必要行的一行数(例如id 5)。

换句话说,我想得到队列条目的编号

1 个答案:

答案 0 :(得分:0)

如果有人有兴趣,这就是答案

import UIKit

final class SelectionView<T: UIView>: UIView {

    var onTap: ((_ isSelected: Bool) -> ())?

    // MARK: - Private

    private let view: T
    private let button = UIButton(type: .custom)
    private var isSelected: Bool = false

    // MARK: - Init

    init(view: T) {
        self.view = view

        super.init(frame: .zero)

        setUp()
    }

    // MARK: - Private

    private func setUp() {
        addSubview(view)
        addSubview(button)

        button.addTarget(self, action: #selector(onButtonTap), for: .touchUpInside)
    }

    @objc private func onButtonTap() {
        isSelected = !isSelected

        onTap?(isSelected)
    }

    // MARK: - Layout

    override func layoutSubviews() {
        super.layoutSubviews()

        view.frame = bounds
        button.frame = bounds
    }

    override func sizeThatFits(_ size: CGSize) -> CGSize {
        return view.sizeThatFits(size)
    }

    // MARK: - Unused

    override init(frame: CGRect) {
        fatalError("init(frame:) has not been implemented")
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

final class BaseView: UIView {

    init() {
        super.init(frame: .zero)

        let views = [SelectionView(view: UIView()), SelectionView(view: UIView())]
        for view in views {
            view.onTap = { [weak self, weak view] isSelected in
                guard let selectedView = view
                    else { return }

                if isSelected {
                    self?.bringSubview(toFront: selectedView)
                }
            }
        }
    }

    // MARK: - Unused

    override init(frame: CGRect) {
        fatalError("init(frame:) has not been implemented")
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

但现在还有另一个问题。如何在Larabel 5.6中实现?

UP 他做到了。