我有这个SQL,运行大约需要2.5秒。
select SUM(valorlanca0_.VALOR_PREVISTO) as col_0_0_
from CF_VALOR_LANCADO_DETALHADO valorlanca0_
inner join CF_VALOR_LANCADO valorlanca1_ on valorlanca0_.ID_VALOR_LANCADO=valorlanca1_.ID_VALOR_LANCADO
inner join CF_LANCAMENTO lancamento2_ on valorlanca1_.ID_LANCAMENTO=lancamento2_.ID_LANCAMENTO
inner join CF_ADMINISTRACAO administra12_ on lancamento2_.ID_ADMINISTRACAO=administra12_.ID_ADMINISTRACAO
inner join CF_EMPRESA empresa13_ on lancamento2_.ID_EMPRESA=empresa13_.ID_EMPRESA
inner join CF_USUARIO usuario14_ on lancamento2_.ID_USUARIO_CRIOU=usuario14_.ID_USUARIO
left outer join CF_FORMA_PAGAMENTO formapagam9_ on valorlanca1_.ID_FORMA_PAGAMENTO=formapagam9_.ID_FORMA_PAGAMENTO
inner join CF_CONTA conta10_ on valorlanca1_.ID_CONTA=conta10_.ID_CONTA
left outer join CF_FATURA fatura11_ on valorlanca1_.ID_FATURA=fatura11_.ID_FATURA
left outer join CF_CATEGORIA categoria3_ on valorlanca0_.ID_CATEGORIA=categoria3_.ID_CATEGORIA
left outer join CF_CENTRO_CUSTO centrocust4_ on valorlanca0_.ID_CENTRO_CUSTO=centrocust4_.ID_CENTRO_CUSTO
left outer join CF_FAV_FONTE_PAGADORA favfontepa5_ on valorlanca0_.ID_FAV_FONTE_PAGADORA=favfontepa5_.ID_FAV_FONTE_PAGADORA
left outer join CF_CONTA_CONTABIL contaconta6_ on valorlanca0_.ID_CONTA_CONTABIL=contaconta6_.ID_CONTA_CONTABIL
left outer join CF_CONTATO contato7_ on valorlanca0_.ID_CONTATO=contato7_.ID_CONTATO
left outer join CF_MARCA marca8_ on valorlanca0_.ID_MARCA=marca8_.ID_MARCA
where administra12_.ID_ADMINISTRACAO=406 and lancamento2_.TIPO_CONTA=2 and (conta10_.ID_CONTA in (2060, 404, 405, 4291, 406, 410, 4292, 403, 4355, 402, 407)) and conta10_.TIPO<>9 and lancamento2_.TIPO_TRANSACAO=10
and (valorlanca1_.SITUACAO in (1)) and ((valorlanca1_.DATA_PREVISTA<='2015-07-22' and valorlanca1_.SITUACAO=1 or valorlanca1_.DATA_BAIXA<='2015-07-22' and valorlanca1_.SITUACAO=3)
and conta10_.TIPO<>2 or fatura11_.DATA_VENCIMENTO<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=1 or valorlanca1_.DATA_BAIXA<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=3)
and ((empresa13_.ID_EMPRESA in (422, 3643)) and usuario14_.ID_USUARIO=574 or empresa13_.ID_EMPRESA in (422, 3643))
这是解释命令
1 SIMPLE administra12_ const PRIMARY PRIMARY 8 const 1 Using index
1 SIMPLE empresa13_ range PRIMARY PRIMARY 8 2 Using where; Using index
1 SIMPLE lancamento2_ ref PRIMARY,FKE50FD2D68AC234EC,FKE50FD2D6574FCEF7,FKE50FD2D628D2EAE8,IDXEMPRESA IDXEMPRESA 8 controlese.empresa13_.ID_EMPRESA 225 Using index condition; Using where
1 SIMPLE valorlanca1_ ref PRIMARY,FK49527EEB12DDD0DA,FK49527EEBDDD55138,IDX_VL_IDL,IDX_VL_IVL FK49527EEB12DDD0DA 8 controlese.lancamento2_.ID_LANCAMENTO 1 Using where
1 SIMPLE conta10_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca1_.ID_CONTA 1 Using where
1 SIMPLE usuario14_ eq_ref PRIMARY PRIMARY 8 controlese.lancamento2_.ID_USUARIO_CRIOU 1 Using index
1 SIMPLE fatura11_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca1_.ID_FATURA 1 Using where
1 SIMPLE formapagam9_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca1_.ID_FORMA_PAGAMENTO 1 Using index
1 SIMPLE valorlanca0_ ref FK60A3C74EA9A01AC3,IDX_VLD_IDVL FK60A3C74EA9A01AC3 8 controlese.valorlanca1_.ID_VALOR_LANCADO 1
1 SIMPLE categoria3_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca0_.ID_CATEGORIA 1 Using index
1 SIMPLE centrocust4_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca0_.ID_CENTRO_CUSTO 1 Using index
1 SIMPLE favfontepa5_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca0_.ID_FAV_FONTE_PAGADORA 1 Using index
1 SIMPLE contaconta6_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca0_.ID_CONTA_CONTABIL 1 Using index
1 SIMPLE contato7_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca0_.ID_CONTATO 1 Using index
1 SIMPLE marca8_ eq_ref PRIMARY PRIMARY 8 controlese.valorlanca0_.ID_MARCA 1 Using index
最大的表是CF_VALOR_LANCADO(855m记录)和CF_VALOR_LANCADO_DETALHADO(860m记录)。
我可以做些什么来优化我的选择?
答案 0 :(得分:1)
查询的一个地狱:)
您可以先删除未使用的表格,如下所示:
select SUM(valorlanca0_.VALOR_PREVISTO) as col_0_0_
from CF_VALOR_LANCADO_DETALHADO valorlanca0_
inner join CF_VALOR_LANCADO valorlanca1_ on valorlanca0_.ID_VALOR_LANCADO=valorlanca1_.ID_VALOR_LANCADO
inner join CF_LANCAMENTO lancamento2_ on valorlanca1_.ID_LANCAMENTO=lancamento2_.ID_LANCAMENTO
inner join CF_ADMINISTRACAO administra12_ on lancamento2_.ID_ADMINISTRACAO=administra12_.ID_ADMINISTRACAO
inner join CF_EMPRESA empresa13_ on lancamento2_.ID_EMPRESA=empresa13_.ID_EMPRESA
inner join CF_USUARIO usuario14_ on lancamento2_.ID_USUARIO_CRIOU=usuario14_.ID_USUARIO
inner join CF_CONTA conta10_ on valorlanca1_.ID_CONTA=conta10_.ID_CONTA
left outer join CF_FATURA fatura11_ on valorlanca1_.ID_FATURA=fatura11_.ID_FATURA
where administra12_.ID_ADMINISTRACAO=406
and lancamento2_.TIPO_CONTA=2
and (conta10_.ID_CONTA in (2060, 404, 405, 4291, 406, 410, 4292, 403, 4355, 402, 407))
and conta10_.TIPO<>9
and lancamento2_.TIPO_TRANSACAO=10
and (valorlanca1_.SITUACAO in (1))
and ((valorlanca1_.DATA_PREVISTA<='2015-07-22' and valorlanca1_.SITUACAO=1 or valorlanca1_.DATA_BAIXA<='2015-07-22' and valorlanca1_.SITUACAO=3) and conta10_.TIPO<>2
or fatura11_.DATA_VENCIMENTO<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=1
or valorlanca1_.DATA_BAIXA<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=3
)
and ((empresa13_.ID_EMPRESA in (422, 3643)) and usuario14_.ID_USUARIO=574 or empresa13_.ID_EMPRESA in (422, 3643))
希望它有助于升技:)
还有一个(SQL-Server可能只是自己这样做)
and ((empresa13_.ID_EMPRESA in (422, 3643)) and usuario14_.ID_USUARIO=574 or empresa13_.ID_EMPRESA in (422, 3643))
等同于
and empresa13_.ID_EMPRESA in (422, 3643)
你也可以尝试这种改变(95%确定它们是等效的) - 没有嵌套的&#34;或者#34;,这有时会有助于我的体验。
and (
(valorlanca1_.DATA_PREVISTA<='2015-07-22' and valorlanca1_.SITUACAO=1
or valorlanca1_.DATA_BAIXA<='2015-07-22' and valorlanca1_.SITUACAO=3
) and conta10_.TIPO<>2
or fatura11_.DATA_VENCIMENTO<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=1
or valorlanca1_.DATA_BAIXA<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=3
)
要:
and (
valorlanca1_.DATA_PREVISTA <='2015-07-22' and valorlanca1_.SITUACAO=1 and conta10_.TIPO<>2
or fatura11_.DATA_VENCIMENTO <='2015-07-22' and valorlanca1_.SITUACAO=1 and conta10_.TIPO=2
or valorlanca1_.DATA_BAIXA <='2015-07-22' and valorlanca1_.SITUACAO=3
)
答案 1 :(得分:0)
我需要查看您在CF_VALOR_LANCADO_DETALHADO
和CF_VALOR_LANCADO
上创建的索引,但是您考虑过Composite Index
吗?这使您可以在多于1列上创建索引。
作为猜测,我会考虑创建一个multiple column index
CF_VALOR_LANCADO.DATA_PREVISTA
和CF_VALOR_LANCADO.SITUACAO
答案 2 :(得分:0)
您的查询的EXPLAIN一点都不错
您可以在MySQL服务器上运行这些SQL语句并在此处发布结果并发布您的MySQl服务器版本吗? 通过这些语句,我们可以看到Query是CPU还是I / O限制。
SET profiling = 1;
select SUM(valorlanca0_.VALOR_PREVISTO) as col_0_0_
from CF_VALOR_LANCADO_DETALHADO valorlanca0_
inner join CF_VALOR_LANCADO valorlanca1_ on valorlanca0_.ID_VALOR_LANCADO=valorlanca1_.ID_VALOR_LANCADO
inner join CF_LANCAMENTO lancamento2_ on valorlanca1_.ID_LANCAMENTO=lancamento2_.ID_LANCAMENTO
inner join CF_ADMINISTRACAO administra12_ on lancamento2_.ID_ADMINISTRACAO=administra12_.ID_ADMINISTRACAO
inner join CF_EMPRESA empresa13_ on lancamento2_.ID_EMPRESA=empresa13_.ID_EMPRESA
inner join CF_USUARIO usuario14_ on lancamento2_.ID_USUARIO_CRIOU=usuario14_.ID_USUARIO
left outer join CF_FORMA_PAGAMENTO formapagam9_ on valorlanca1_.ID_FORMA_PAGAMENTO=formapagam9_.ID_FORMA_PAGAMENTO
inner join CF_CONTA conta10_ on valorlanca1_.ID_CONTA=conta10_.ID_CONTA
left outer join CF_FATURA fatura11_ on valorlanca1_.ID_FATURA=fatura11_.ID_FATURA
left outer join CF_CATEGORIA categoria3_ on valorlanca0_.ID_CATEGORIA=categoria3_.ID_CATEGORIA
left outer join CF_CENTRO_CUSTO centrocust4_ on valorlanca0_.ID_CENTRO_CUSTO=centrocust4_.ID_CENTRO_CUSTO
left outer join CF_FAV_FONTE_PAGADORA favfontepa5_ on valorlanca0_.ID_FAV_FONTE_PAGADORA=favfontepa5_.ID_FAV_FONTE_PAGADORA
left outer join CF_CONTA_CONTABIL contaconta6_ on valorlanca0_.ID_CONTA_CONTABIL=contaconta6_.ID_CONTA_CONTABIL
left outer join CF_CONTATO contato7_ on valorlanca0_.ID_CONTATO=contato7_.ID_CONTATO
left outer join CF_MARCA marca8_ on valorlanca0_.ID_MARCA=marca8_.ID_MARCA
where administra12_.ID_ADMINISTRACAO=406 and lancamento2_.TIPO_CONTA=2 and (conta10_.ID_CONTA in (2060, 404, 405, 4291, 406, 410, 4292, 403, 4355, 402, 407)) and conta10_.TIPO<>9 and lancamento2_.TIPO_TRANSACAO=10
and (valorlanca1_.SITUACAO in (1)) and ((valorlanca1_.DATA_PREVISTA<='2015-07-22' and valorlanca1_.SITUACAO=1 or valorlanca1_.DATA_BAIXA<='2015-07-22' and valorlanca1_.SITUACAO=3)
and conta10_.TIPO<>2 or fatura11_.DATA_VENCIMENTO<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=1 or valorlanca1_.DATA_BAIXA<='2015-07-22' and conta10_.TIPO=2 and valorlanca1_.SITUACAO=3)
and ((empresa13_.ID_EMPRESA in (422, 3643)) and usuario14_.ID_USUARIO=574 or empresa13_.ID_EMPRESA in (422, 3643));
SHOW PROFILES; # Displays an table with records use it to find your select profile id
SHOW PROFILE ALL FOR QUERY [select profile_id]
由于JOINS数量众多,因此大多数可信统计数据在PROFILE中具有较高的持续时间和CPU_User。
MySQL将计算表格排列,以找到执行的最佳查询计划。
见下面的代码
/* Calculate how to do the join */
thd_proc_info(thd, "statistics");
if (make_join_statistics(this, select_lex->leaf_tables, conds, &keyuse) ||
thd->is_fatal_error)
{
DBUG_PRINT("error",("Error: make_join_statistics() failed"));
DBUG_RETURN(1);
}
make_join_statistics()函数是一个非常繁重的函数。
答案 3 :(得分:0)
我的推荐是你拆分查询并尝试查看什么是较慢的连接。
还有像
这样的东西and **(valorlanca1_.SITUACAO in (1))**
and ((valorlanca1_.DATA_PREVISTA<='2015-07-22'
and **valorlanca1_.SITUACAO=1** or valorlanca1_.DATA_BAIXA<='2015-07-22'
and **valorlanca1_.SITUACAO=3**)
SITUACAO in (1)
应为SITUACAO = 1
但是你有AND SITUACAO = 3
没有意义。那个和MortenGrueSørensen的评论让我觉得你应该检查你的架构。
即使AND OR
具有优先权,也可以使用( )
帮助您轻松阅读查询。
答案 4 :(得分:0)
首先,我开始清理原始查询的格式以查看表的相关性。然后我改为使用别名来简化更长的表名到更短的时间并想出了这个。
select
SUM(V0.VALOR_PREVISTO) as col_0_0_
from
CF_VALOR_LANCADO_DETALHADO V0
inner join CF_VALOR_LANCADO V1
on V0.ID_VALOR_LANCADO = V1.ID_VALOR_LANCADO
inner join CF_LANCAMENTO L2
on V1.ID_LANCAMENTO = L2.ID_LANCAMENTO
inner join CF_ADMINISTRACAO A12
on L2.ID_ADMINISTRACAO = A12.ID_ADMINISTRACAO
inner join CF_EMPRESA E13
on L2.ID_EMPRESA = E13.ID_EMPRESA
inner join CF_USUARIO U14
on L2.ID_USUARIO_CRIOU = U14.ID_USUARIO
left outer join CF_FORMA_PAGAMENTO F9
on V1.ID_FORMA_PAGAMENTO = F9.ID_FORMA_PAGAMENTO
inner join CF_CONTA C10
on V1.ID_CONTA = C10.ID_CONTA
left outer join CF_FATURA F11
on V1.ID_FATURA = F11.ID_FATURA
left outer join CF_CATEGORIA C3
on V0.ID_CATEGORIA = C3.ID_CATEGORIA
left outer join CF_CENTRO_CUSTO C4
on V0.ID_CENTRO_CUSTO = C4.ID_CENTRO_CUSTO
left outer join CF_FAV_FONTE_PAGADORA F5
on V0.ID_FAV_FONTE_PAGADORA = F5.ID_FAV_FONTE_PAGADORA
left outer join CF_CONTA_CONTABIL C6
on V0.ID_CONTA_CONTABIL = C6.ID_CONTA_CONTABIL
left outer join CF_CONTATO C7
on V0.ID_CONTATO = C7.ID_CONTATO
left outer join CF_MARCA M8
on V0.ID_MARCA = M8.ID_MARCA
where
A12.ID_ADMINISTRACAO = 406
and L2.TIPO_CONTA = 2
and C10.ID_CONTA in (2060, 404, 405, 4291, 406, 410, 4292, 403, 4355, 402, 407)
and C10.TIPO <> 9
and L2.TIPO_TRANSACAO = 10
and V1.SITUACAO in (1)
and ( ( V1.DATA_PREVISTA <= '2015-07-22'
and V1.SITUACAO = 1
or V1.DATA_BAIXA <= '2015-07-22'
and V1.SITUACAO=3 )
and C10.TIPO <> 2
or F11.DATA_VENCIMENTO <= '2015-07-22'
and C10.TIPO = 2
and V1.SITUACAO = 1
or V1.DATA_BAIXA <= '2015-07-22'
and C10.TIPO = 2
and V1.SITUACAO = 3 )
and ( E13.ID_EMPRESA in (422, 3643)
and U14.ID_USUARIO = 574
or E13.ID_EMPRESA in (422, 3643) )
现在,从此开始,查看最后两个AND(...)标准部分。你正在投掷&#34; OR&#34;他们的条件使他们有资格,这可能不是意图,可能意味着不同的东西。
首先...
and ( ( V1.DATA_PREVISTA <= '2015-07-22'
and V1.SITUACAO = 1
or V1.DATA_BAIXA <= '2015-07-22'
and V1.SITUACAO=3 )
也许应该明确
and ( ( ( V1.DATA_PREVISTA <= '2015-07-22'
and V1.SITUACAO = 1 )
or ( V1.DATA_BAIXA <= '2015-07-22'
and V1.SITUACAO=3 )
)
同样......如果这些中的任何一个与OR错误地分组,包括它应该在哪里?
and C10.TIPO <> 2
or ( F11.DATA_VENCIMENTO <= '2015-07-22'
and C10.TIPO = 2
and V1.SITUACAO = 1 )
or ( V1.DATA_BAIXA <= '2015-07-22'
and C10.TIPO = 2
and V1.SITUACAO = 3 )
其次...
and ( E13.ID_EMPRESA in (422, 3643)
and U14.ID_USUARIO = 574
or E13.ID_EMPRESA in (422, 3643) )
由于此处的最后一个OR条件与第一个相同,因此不需要ID_USUARIO = 574,可以简化为......
and E13.ID_EMPRESA in (422, 3643)
你有几个左连接(功能相同于&#34;左外连接&#34;)没有在任何标准中使用...删除它们包括......
LEFT JOIN CF_FORMA_PAGAMENTO
left join CF_CATEGORIA
left join CF_CENTRO_CUSTO
left join CF_CONTA_CONTABIL
left join CF_CONTATO
left join CF_MARCA
您正在使用LEFT-JOIN CF_FATURA fatura11_并将其置于OR条件下,实际上是将其转换为INNER JOIN,因为您不允许使用NULL,但显式测试&#34; DATA_VENCIMENTO&lt; = &#39; 2015年7月22日&#39;&#34;
使用(原始和/或标准组合)简化结果......
select
SUM(V0.VALOR_PREVISTO) as col_0_0_
from
CF_VALOR_LANCADO_DETALHADO V0
inner join CF_VALOR_LANCADO V1
on V0.ID_VALOR_LANCADO = V1.ID_VALOR_LANCADO
inner join CF_LANCAMENTO L2
on V1.ID_LANCAMENTO = L2.ID_LANCAMENTO
inner join CF_ADMINISTRACAO A12
on L2.ID_ADMINISTRACAO = A12.ID_ADMINISTRACAO
inner join CF_EMPRESA E13
on L2.ID_EMPRESA = E13.ID_EMPRESA
inner join CF_USUARIO U14
on L2.ID_USUARIO_CRIOU = U14.ID_USUARIO
left join CF_FORMA_PAGAMENTO F9
on V1.ID_FORMA_PAGAMENTO = F9.ID_FORMA_PAGAMENTO
inner join CF_CONTA C10
on V1.ID_CONTA = C10.ID_CONTA
left join CF_FATURA F11
on V1.ID_FATURA = F11.ID_FATURA
where
A12.ID_ADMINISTRACAO = 406
and L2.TIPO_CONTA = 2
and C10.ID_CONTA in (2060, 404, 405, 4291, 406, 410, 4292, 403, 4355, 402, 407)
and C10.TIPO <> 9
and L2.TIPO_TRANSACAO = 10
and V1.SITUACAO in (1)
and ( ( V1.DATA_PREVISTA <= '2015-07-22'
and V1.SITUACAO = 1
or V1.DATA_BAIXA <= '2015-07-22'
and V1.SITUACAO=3 )
and C10.TIPO <> 2
or F11.DATA_VENCIMENTO <= '2015-07-22'
and C10.TIPO = 2
and V1.SITUACAO = 1
or V1.DATA_BAIXA <= '2015-07-22'
and C10.TIPO = 2
and V1.SITUACAO = 3 )
and ( E13.ID_EMPRESA in (422, 3643)
and U14.ID_USUARIO = 574
or E13.ID_EMPRESA in (422, 3643) )
现在,要优化...我在这里提供的索引可能会通过
显着提高性能Table Index
CF_VALOR_LANCADO_DETALHADO ( ID_VALOR_LANCADO, VALOR_PREVISTO )
CF_VALOR_LANCADO ( SITUACAO, DATA_PREVISTA, DATA_BAIXA, ID_VALOR_LANCADO, ID_LANCAMENTO, ID_FORMA_PAGAMENTO, ID_CONTA, ID_FATURA )
CF_LANCAMENTO ( TIPO_CONTA, TIPO_TRANSACAO, ID_LANCAMENTO, ID_ADMINISTRACAO, ID_EMPRESA, ID_USUARIO_CRIOU )
CF_ADMINISTRACAO ( ID_ADMINISTRACAO )
CF_EMPRESA ( ID_EMPRESA )
CF_USUARIO ( ID_USUARIO )
CF_FORMA_PAGAMENTO ( ID_FORMA_PAGAMENTO )
CF_CONTA ( TIPO, ID_CONTA)
CF_FATURA ( ID_FATURA, DATA_VENCIMENTO )
最后,为了更好地查看和公开您的标准被简化的位置,我会将具有明确条件的那些移动到相应的JOIN / ON条件中,但让我们看看...中的取消标准。
and V1.SITUACAO in (1)
and ( ( V1.DATA_PREVISTA <= '2015-07-22'
and V1.SITUACAO = 1
or V1.DATA_BAIXA <= '2015-07-22'
and V1.SITUACAO=3 )
SITUACAO IN(1)的第一部分是立即取消(paren)部分中的SITUACAO = 3,但我认为你真正想要的是......
and V1.SITUACAO in (1) <--- REMOVE THIS LINE, and add parens below for data/situacao pairs
and ( ( ( V1.DATA_PREVISTA <= '2015-07-22'
and V1.SITUACAO = 1 )
or ( V1.DATA_BAIXA <= '2015-07-22'
and V1.SITUACAO=3 )
)
至于你之后的其他可能相互冲突的AND / OR条件,仔细看看你得到的是什么
答案 5 :(得分:0)
public void MainMenu()
{
ConsoleKeyInfo _key;
do
{
Console.WriteLine("Main Menu");
Console.WriteLine("Press 1 for cars");
Console.WriteLine("Press 2 for planes");
Console.WriteLine("Press 3 for boats");
Console.WriteLine("Enter 'q' to exit");
_key = Console.ReadKey();
switch ((char)_key.Key)
{
case '1':
{
Console.Clear();
CarMenu();
break;
}
case '2':
{
Console.Clear();
PlaneMenu();
break;
}
case '3':
{
Console.Clear();
BoatMenu();
break;
}
case 'Q':
{
Environment.Exit(0);
break;
}
default:
{
Console.WriteLine("No options to that key...");
Console.WriteLine("-------------------------\n\n");
break;
}
}
} while (true);
}
public void CarMenu()
{
do
{
Console.Clear();
Console.WriteLine("Car menu");
Console.WriteLine("Press 1 to list all cars");
Console.WriteLine("Press 2 to list single car");
Console.WriteLine("Press 3 to register a new car");
Console.WriteLine("Press 0 for main menu");
Console.WriteLine("Enter 'q' to exit");
_key = Console.ReadKey();
Console.WriteLine((char)_key.Key);
Console.ReadKey();
switch ((char)_key.Key)
{
case '1':
{
Console.Clear();
_handler.listAllDevices();
break;
}
case '2':
{
Console.Clear();
PlaneMenu();
break;
}
case '3':
{
Console.Clear();
BoatMenu();
break;
}
case '0':
{
Console.Clear();
MainMenu();
break;
}
case 'Q':
{
Environment.Exit(0);
break;
}
default:
{
Console.WriteLine("No options to that key...");
Console.WriteLine("-------------------------\n\n");
break;
}
}
} while (true);
}
有时会通过转换为OR
:
UNION
- &GT;
SELECT ...
WHERE ((x=1) OR (y=2))
(( SELECT ...
WHERE (x=1)
)
UNION DISTINCT
( SELECT ...
WHERE (y=2)
)
比UNION DISTINCT
慢,但您可能需要它来进行去除。)