Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 用一个子集按三个集合对结果进行排序_Sql_Sqlite_Transactions_Relational Database - Fatal编程技术网

Sql 用一个子集按三个集合对结果进行排序

Sql 用一个子集按三个集合对结果进行排序,sql,sqlite,transactions,relational-database,Sql,Sqlite,Transactions,Relational Database,我有三个问题 如果“union all”之前的第一个查询是查询A,第二个和第三个分别是B和C,我该怎么办: select stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,quantita from comanda where contiene_variante='1' and ntav_comanda='25' and posizione='CONTO' and s

我有三个问题

如果“union all”之前的第一个查询是查询A,第二个和第三个分别是B和C,我该怎么办:

select stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,quantita from comanda where contiene_variante='1' and ntav_comanda='25' and posizione='CONTO' and stato_record='ATTIVO'   and numero_conto ="1" 

                        union all

select stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,sum(quantita) as quantita from comanda where (contiene_variante !='1' or contiene_variante is null) and length(nodo)=3 and ntav_comanda='25' and posizione='CONTO' and stato_record='ATTIVO'  and numero_conto ="1"  group by desc_art

                        union all

select stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,quantita from comanda where length(nodo)=7 and ntav_comanda='25'  and posizione='CONTO' and stato_record='ATTIVO'  and numero_conto ="1"  order by nodo asc;
我需要做:

(A(B ORDER BY B ASC),C) ORDER BY (A,C) ASC
然后结果将是,例如:

Extract A
Extract B of A (by node) AND order alphabetical in the internal
Extract C 
Then order by A (and B is an A subset),C alphabetical
而不是按节点随机排序,如:

C   Bitter
A   Coca
B   + Ice
B   + Lemon
B   + Orange juice
A   Juice
B   + Lemon
C   Orange cup
C   Spaghetti

我希望我已经说清楚了。

我修正了这个问题:

C   Orange cup
A   Juice
B   + Lemon
C   Bitter
A   Coca
B   + Orange juice
B   + Ice
B   + Lemon
C   Spaghetti
截图:

谢谢你的帮助。

A/B/C的行为就像桌子一样。你说的“A点餐”是什么意思?使用哪一列?
select  substr(desc_art,1,3)||'MA'|| substr(nodo,1,3) as ord,stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,quantita from comanda as c1 where contiene_variante='1' and ntav_comanda='34'  and posizione='CONTO' and stato_record='ATTIVO' and  numero_conto ="1"  
union all
select  substr(desc_art,1,3)||'MA'||substr(nodo,1,3) as ord,stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,sum(quantita) as quantita from comanda as c1 where (contiene_variante !='1' or contiene_variante is null) and length(nodo)=3 and ntav_comanda='34' and posizione='CONTO' and stato_record='ATTIVO'  and numero_conto ="1"   group by desc_art
union all       
select  (select substr(desc_art,1,3) from comanda where nodo=substr(c1.nodo,1,3)  and ntav_comanda='34')||'MB' ||substr(nodo,1,3) as ord,stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,quantita from comanda as c1 where length(nodo)=7 and substr(desc_art,1,1)='-' and ntav_comanda='34'   and posizione='CONTO' and stato_record='ATTIVO'  and numero_conto ="1"  
union all
select (select substr(desc_art,1,3) from comanda where nodo=substr(c1.nodo,1,3) and ntav_comanda='34')||'MC'||substr(nodo,1,3) as ord,stampata_sn,numero_conto,dest_stampa,portata,categoria,prog_inser,nodo,desc_art,prezzo_un,quantita from comanda as c1 where length(nodo)=7 and substr(desc_art,1,1)!='-' and ntav_comanda='34'  and posizione='CONTO' and stato_record='ATTIVO'  and numero_conto ="1"   
order by ord ASC;