Skip to content

Instantly share code, notes, and snippets.

@sqlparser
Created December 12, 2023 08:17
Show Gist options
  • Save sqlparser/c6bd318491ea415633a2b12d88c7fd92 to your computer and use it in GitHub Desktop.
Save sqlparser/c6bd318491ea415633a2b12d88c7fd92 to your computer and use it in GitHub Desktop.
Sybase Sample SQL
```sql
-- sybase sample sql
create view accounts (title, advance, amt_due)
as select title, advance, price * total_sales
from titles
where price > $5
create view cities
(authorname, acity, publishername, pcity)
as select authors.au_lname, authors.city, publishers.pub_name,
publishers.city
from authors, publishers
where authors.city = publishers.city;
create view cities2
as select authorname = authors.au_lname,
acity = authors.city, publishername = authors.pub_name, pcity =
publishers.city
from authors, publishers
where authors.city = publishers.city
;
create view psych_titles as
select *
from (select * from titles
where type = "psychology") dt_psych
;
insert newpublishers (pub_id, pub_name)
select pub_id, pub_name
from publishers
where pub_name="New Age Data"
;
merge into GlobalSales
(Item_number, Description, Quantity)as G
using DailySales as D
ON D.Item_number = G.Item_number
when not matched
then
insert (Item_number, Description, Quantity )
values (D.Item_number, D.Description, D.Quantity)
when matched
then update set
G.Quantity = G.Quantity + D.Quantity
;
update titles
set total_sales = sales.total_sales + sales.qty
from titles, salesdetail, sales
where titles.title_id = salesdetail.title_id
and salesdetail.stor_id = sales.stor_id
and salesdetail.ord_num = sales.ord_num
and sales.date in
(select max (sales.date) from sales)
;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment