本文介绍了在mysql中使用if else condtion和union选择查询 - 获取sql错误1604的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中有这样的查询,



如果condition =''那么

从col选择col1,col2,col3按col2排序;

其他

(从col中选择col1,col2,col3,其中col2不为null)

union

(从col中选择col1,col2,col3,其中col1不为null)

订购

col2;



得到sql错误1604



请让我知道是什么问题。

i have query like this in my procedure,

if condition='' then
select col1, col2, col3 from col order by col2;
else
(select col1, col2, col3 from col where col2 is not null)
union
(select col1,col2,col3 from col where col1 is not null)
order by
col2;

getting sql error 1604

Please let me know what is the problem.

推荐答案

IF condition='' THEN
    SELECT col1, col2, col3
    FROM Table1
    ORDER BY col2;
ELSE
    SELECT T.*
    FROM 
    (select col1, col2, col3
     FROM Table1
     WHERE col2 is not null
    UNION ALL
    select col1, col2, col3
    FROM Table2
    WHERE col1 is not null) AS T
    ORDER BY T.col2;
END IF;


IF condition='' THEN
    SELECT col1, col2, col3 FROM col ORDER BY col2;
ELSE
    (SELECT col1, col2, col3 FROM col WHERE col2 IS NOT NULL)
    UNION
    (SELECT col1, col2, col3 FROM col WHERE col1 IS NOT NULL)
    ORDER BY col2;
END IF;





参考文献:

[]

[]


这篇关于在mysql中使用if else condtion和union选择查询 - 获取sql错误1604的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 04:11