- .separator ","
- create TABLE tab(L1 int, T TEXT, L2 INT, L3 INT, L4 INT);
- .help
- .import filename.txt tab
- .tables wyświetla tabele
- select * from tab (limit x); wyświetla wszystko z tabeli
- .headers on - włącza nagłówki
- .width 5 20 5 5 5 szerokość
- .mode column tryb kolumny
- select count(*) from tab; sprawdza ile jest jest wierszy w tabeli
- select count (L4) from tab where strftime('%Y',T)='2007'; wypisuje ilość elementów tabeli L4 dla roku 2007
- select T,L4 from tab where strftime('%Y',T)='2007';
- select strftime('%m',T), sum(L4) from tab where strftime('%Y',T) = '2007' group by strftime('%m',T); -wypisuje sume z tabeli L4 miesiąc po miesiącu dla roku 2007
- select count (distinct L1) from tab; pokazuje ilość L1
- select sum(L4) from tab where strftime('%Y', T )="2007"; ile przelewów było w 2007
- as Nazwa - zmienia nazwe tabeli
- select strftime('%w',T) as dzien , sum(L4) as suma from tab group by strftime('%w',T); - całkowita suma L4 z całego pliku dla każdego dnia tygfodnia
- .save nazwa
- .quit
- sqlite 3 nazwa
- insert into nazwa_tabeli distinct ddd,eee from nazwa_tabeli; - dodaje z jednej tabeli do drugiej
- drop table nazwa; - usuwa tabele
- select strftime('%w',DATA),count(*) from BANKOMACIKI group by strftime('%w',DATA); - ile razy byl uzywany bankomat kazdego dnia
- .restore BANKOMATKI
- mysql 14.11.14
- set @liczba=2/3; //zmienna uzytkownika
- select @liczba;
- show variables; //pokazuje zmienne mysql
- wcześniej użyć use baza1;
- select * from city where name = "Krakow";
- select * from city where name = "Krakow"\G;
- select * from city where name like "Kra%"; //%zastepuje dowolny lancuch znakow, szukamy miast z Kra w nazwie
- \T H:/cos/costam.txt //otwiera plik
- tutaj operacje ktore zapisuje do pliku...
- \t //zamyka plik tadam
- \s wyświetla informacje ciekawe bardzo jakiej bazy uzywamy itd
- select name, lifeexperiemcy, REPEAT("*", lifeexperiency) from country where continent="Asia";
- select name, LifeExpectancy, REPEAT("*", LifeExpectancy) from country where continent = "Asia";
- select name, 1000000*gnpold/population as GNPPC_old,
- 1000000*gnp/population as GNPPP_new, floor(((100*1000000*gnp/population)/(1000000*gnpold/population)-100)/2) as procent, repeat("*",floor(GNP*100/GNPold-100)/2), from country where continent = "Europe" and GNP is not null and GNPold is not null;
- 21.11.14
- SELECT name, max(100000*gnp/population) from country
- select continent, max(100000*gnp/population) from country group by continent
- zapisywanie do zmiannej
- select max(1000000*gnp/population)from country int @maxgnp
- select name, floor(lifexpetancy/10) from country order by 2 desc limit 10
- i jak uruchomić skrypt:
- umieszczamy w folderze z binarnymi i \.skrypt7.sql
- 28.11.14
- dalej database world w mysql
- kwartyle populacja przez powierzchnie kraju
- select * from country limit 1\G
- select population/surfacearea from country limit 1\G
- select code, population/surfacearea from country limit 10
- select code, population/surfacearea from country where population > 0 and surfacearea > 0.1 order by 2 desc (lub asc);
- select name,code, round(population/surfacearea,2) as dupa from country where population > 0 and surfacearea > 0.1 order by 2 desc (lub asc) limit 117;
- ten set mi nie działa nie wiem czemu :(
- set @q2=select name,code, round(population/surfacearea,2) as dupa from country where population > 0 and surfacearea > 0.1 order by 2 desc (lub asc) limit 117;
- napisz procedurę która nazywa się ttLiveEx (temporary table life excośtam) ma przyjmować dwa parametry tekstowe (dwa kody) np. 'Rus' 'Pol'. w wyniku ma być tabela tymczasowa z trzema kolumnami. zawartością mają być wszystkie kraje od rosji do polski uporządkowane według oczekiwanej średniej długości życia. kod pierwszego kraju gdzie się krócej życje i kod drugiego kraju gdzie się dłużej zyje i wszystkie między nimi.
- delimiter // (bo jakbysmy dali ; to chcialby sie wykonać)
- create procedure tt_lifeEx(IN p1 char(3), IN p2 char(3))
- begin
- select round(lifeexpectancy * 10) from country where code=p1 into @poczatek;
- select round(lifeexpectancy * 10) from country where code=p2 into @koniec;
- drop table if exists lifeex;
- create temporary table lifeex as
- (select code, name, lifeexpectancy from country where round(lifeexpectancy*10)
- between @poczatek and @koniec order by 3);
- end#
- delimiter ;
- source skrypt4a.txt
- call tt_lifeEx('RUS','POL');
- select * from lifeex
- jesli istnieje to drop procedure tt_lifeex;
- skrypt7.sql
- 2.0 KB