• Non ci sono risultati.

Generare la classifica con la posizione a partire da una tabella

N/A
N/A
Protected

Academic year: 2021

Condividi "Generare la classifica con la posizione a partire da una tabella"

Copied!
3
0
0

Testo completo

(1)

Delete su più tabelle

DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id;

Or:

DELETE FROM t1,t2 USING t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id;

IF IF(expr1,expr2,expr3)

If expr1 is TRUE (expr1 <> 0 and expr1 <> NULL) then

IF()

returns expr2; otherwise it returns expr3.

IF()

returns a numeric or string value, depending on the context in which it is used.

mysql> SELECT IF(1>2,2,3);

-> 3

mysql> SELECT IF(1<2,'yes','no');

-> 'yes'

mysql> SELECT IF(STRCMP('test','test1'),'no','yes');

-> 'no'

$sql="SELECT * FROM users WHERE DATEDIFF(CURDATE(), IF('register_date'=NULL,CURDATE(), 'register_date')) ='1'";

14.1.5 LOAD DATA INFILE Syntax

Esempio per caricare in una tabella il contenuto del file mysql> LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name -> FIELDS TERMINATED BY ',' ENCLOSED BY '"' -> LINES TERMINATED BY '\n';

14.1.7 SELECT Syntax

Esempio per caricare in unfile il risultato di una select

SELECT a,b,a+b INTO OUTFILE '/tmp/result.text' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM test_table;

14.1.4.1 INSERT ... SELECT

With INSERT ... SELECT, you can quickly insert many rows into a table from one or many tables.

INSERT INTO tbl_temp2 (fld_id) SELECT tbl_temp1.fld_order_id

FROM tbl_temp1 WHERE tbl_temp1.fld_order_id > 100;

14.2.6 CREATE TABLE Syntax

You can create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement:

CREATE TABLE new_tbl SELECT * FROM orig_tbl;

Generare la classifica con la posizione a partire da una tabella

(2)

nomep prezzo

biro 2.5

quaderno 2.5

gomma 0.5

righello 8.5 astuccio 5.5

SET @riga = 0, @posizione = 0, @preced = 0;

SELECT @riga := @riga + 1 AS riga, nomep, @posizione := IF(@preced<>prezzo,@riga,@posizione) AS posizione, @preced := prezzo AS prezzo FROM prodotti ORDER BY prezzo DESC

riga nomep posizione prezzo

1 righello 1 8.5

2 astuccio 2 5.5

3 biro 3 2.5

4 quaderno 3 2.5

5 gomma 5 0.5

(3)

Esame 2002 – Banca del tempo query 1

hadato

datad ored codicepd codicead

NULL 3 1 2

NULL 2 2 2

NULL 2 3 3

haric

datar orer codicepr codicear

NULL 4 3 1

NULL 1 4 2

NULL 6 5 3

select

if(temp.codicepd,temp.codicepd,temp.codicepr) as codice, case

when temp.ored is not NULL and temp.orer is not NULL Then temp.ored - temp.orer when temp.ored is NULL Then - temp.orer

else temp.ored end as debito from

(SELECT * FROM `1hadato` as d left join `1haric` as r on r.codicepr=d.codicepd union

SELECT * FROM `1hadato` as d right join `1haric` as r on r.codicepr=d.codicepd) as temp

codice debito

1 3

2 2

3 -2

4 -1

5 -6

Riferimenti

Documenti correlati

of the tangent bundle w;th the fibre of dimens;on n... l) ho1d in the more genera1 situation of an almost mu1tifo1iated riemannian structures on a manifo1d, l.e.. are not

Others argue that the treaty will hurt the United States economy because reducing greenhouse gases emission will increase the cost of production, thereby making American

Overall, the paper is organized as follows: Section 2 presents the main related image cropping methods and briefly reviews the thumbnail selection literature, Section 3 introduces

C'est ainsi que les consilia pro parte qu'il rendit, gratuitement, pour les Franciscains de sa paroisse à Florence, portent le titre d'allegationes dans le manuscrit vatican

Cosmology, Ministry of Education; Shanghai Key Laboratory for Particle Physics and Cosmology; Institute of Nuclear and Particle Physics, Shanghai 200240, People ’s Republic of China..

Dal principale obiettivo discende poi la seconda RQ e, in particolare, tramite la stessa ci proponiamo di capire quale Strategic Business Unit (aviation o non aviation) si

Models based on intensity have been elaborated exploiting some stochastic differential equations, for example CIR-short rate models.. That

Aim of the present work is to evaluate individual response to DAV-therapy in patients affected by MM in relation to genetic polymorphism of two metabolic enzymes,