![](/img/trans.png)
[英]select two columns from two different tables in the same db using mysql + use the output of query in C#
[英]MySQL-extract a number from db and use it in same query
我的數據庫中的table 1
有很多列,包括id
和time
。 一個 id 被發送到服務器,然后我必須從表中提取其相應的時間(比如說t
)並運行如下查詢:
SELECT * FROM(
(SELECT * FROM table1 WHERE time>t AND ...clause 1...) // query A
UNION
(SELECT * FROM table1 WHERE time>t AND ...clause 2...) // query B
) h LIMIT 24;
如何在上述查詢中包含一個子查詢,該子查詢提取t
並使其可由查詢 A 和查詢 B 訪問?
我想你需要 Mysql WITH (Common Table Expression) 這里,
WITH CTE AS (
SELECT * FROM table1 WHERE time>t
)
SELECT * FROM (
(SELECT * FROM CTE AND ...clause 1...) // query A
UNION
(SELECT * FROM CTE AND ...clause 2...) // query B
) h LIMIT 24;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.