我有 2 个相同的表格,它们具有相同的格式但填充了不同的数据。
我想SELECT
使用group by
并且order by
不想使用 a进行查询,UNION
因为它使我的查询很长。
这是一个有效的示例:
(SELECT a, b, c, d, e, f, g, MIN(h) as h, i
FROM `table1`
WHERE a LIKE '%this%' AND b LIKE '%that%'
GROUP BY b, a,c)
UNION
(SELECT a, b, c, d, e, f, g, MIN(h) as h, i
FROM `table2`
WHERE a LIKE '%this%' AND b LIKE '%that%'
GROUP BY b, a,c)
ORDER BY
b DESC, h ASC, c ASC
有没有更优雅的方式来使查询工作?
就像是
(SELECT a, b, c, d, e, f, g, MIN(h) as h, i
FROM `table1`,`table2`
WHERE a LIKE '%this%' AND b LIKE '%that%'
GROUP BY b, a, c)
ORDER BY
b DESC, h ASC, c ASC`