นี่ครับตัวอย่างโค้ด
select distinct v.hn,v.cid,v.vstdate,p.pname as 'คำนำหน้า',p.fname as 'ชื่อ', p.lname as 'สกุล',pt.name as 'สิทธิ์การรักษา' , n.name as 'เชื้อชาติ'
from vn_stat v
LEFT OUTER JOIN patient p ON p.hn=v.hn
LEFT OUTER JOIN pttype pt ON pt.pttype=v.pttype
LEFT OUTER JOIN nationality n ON n.nationality=p.nationality
left outer join thaiaddress t1 on t1.chwpart=p.chwpart and
t1.amppart="00" and t1.tmbpart="00"
left outer join thaiaddress t2 on t2.chwpart=p.chwpart and
t2.amppart=p.amppart and t2.tmbpart="00"
left outer join thaiaddress t3 on t3.chwpart=p.chwpart and
t3.amppart=p.amppart and t3.tmbpart=p.tmbpart
where spclty in ('12','13','14') and vstdate between '2010-07-01' and '2010-07-31' and
v.pttype in ('10','11','22','23','34','35','36','37','90','91','92','93','94','95','96','98','99')
group by v.hn
ปล. ยัง join table ไม่ครบนะครับ ผม ทดสอบแค่นี่ client ก็ค้างแล้วครับ ก็เลยไม่ได้ทำต่อ
นี่ครับ my.cnf
[client]
port = 3306
socket = /var/lib/mysql/mysql.sock
#basedir = /var/lib/mysql
#datadir = /var/lib/mysql/data
default-character-set=tis620
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 384M
max_allowed_packet = 16M
table_cache = 1M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
max_heap_table_size = 128M
myisam_sort_buffer_size = 128M
thread_cache = 8
query_cache_size= 256M
thread_concurrency = 8
default-character-set=tis620
skip-name-resolve
innodb_file_per_table
skip-character-set-client-handshake
init_connect = 'SET NAMES tis620'
max_connections = 1000
innodb_data_home_dir = /var/lib/mysql/
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql/
############################# mysql 5.1.X
#innodb_log_arch_dir = /var/lib/mysql/
#############################
innodb_buffer_pool_size = 1000M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
#server-id=1
#log-bin
#sync_binlog=1
#innodb_safe_binlog
[mysqldump]
quick
max_allowed_packet = 16M
allow-keywords
[mysql]
no-auto-rehash
default-character-set=tis620
[isamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout