🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.database
Article #1015

Re: ���ʵ������SQL, �����·��ָ�̰�

#1015
From: yoursunny.com
Date: Tue, 17 Jun 2008 00:50
88 lines
3627 bytes
һ����MySQL�п����õĴ��롣
�����Ӳ�ѯ��ʹ����ORDER BY�������SQL��׼��

SELECT td.attr_value AS attr_value
    FROM
    (SELECT *
        FROM table1 AS ta,table2 AS tb
        WHERE ta.row_id=tb.fo_row_id
            AND tb.attr_name='Order'
            AND ta.name='b'
        ORDER BY attr_value
        ) AS tc,table2 AS td
    WHERE tc.entry_row_id=td.entry_row_id
        AND td.attr_name='Name'
    ORDER BY tc.attr_value

���������MySQL/5.0.27-community-nt�в��Գɹ�


ʹ�õ���ݿ��������£�

--
-- ��Ľṹ `table1`
--

CREATE TABLE IF NOT EXISTS `table1` (
  `name` char(1) NOT NULL,
  `row_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- ���������� `table1`
--

INSERT INTO `table1` (`name`, `row_id`) VALUES
('a', 1),
('b', 2);


--
-- ��Ľṹ `table2`
--

CREATE TABLE IF NOT EXISTS `table2` (
  `fo_row_id` int(11) NOT NULL,
  `entry_row_id` int(11) NOT NULL,
  `attr_name` varchar(10) NOT NULL,
  `attr_value` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- ���������� `table2`
--

INSERT INTO `table2` (`fo_row_id`, `entry_row_id`, `attr_name`, 
`attr_value`) VALUES
(1, 0, 'Name', 'Candy'),
(1, 0, 'Order', '1'),
(2, 1, 'Name', 'Mark'),
(2, 1, 'Order', '1'),
(2, 3, 'Name', 'Rube'),
(2, 3, 'Order', '2'),
(2, 2, 'Name', 'Gavin'),
(2, 2, 'Order', '4'),
(2, 4, 'Name', 'Duke'),
(2, 4, 'Order', '3');

�� �� leease (������޹㣬���²��) �Ĵ������ᵽ: ��
: �������Ŀ������������һ��Ҳû�������ôŪ��лл�������
: ��������Table1 �� Table2�ֱ���
: http://bbs.sjtu.edu.cn/file/database/1213288682275251.JPG
: Table2�е�Fo_ROW_ID��Table1��ROW_ID�����Table2�е�һ��Entry_Row_ID���Ӧһ��
: Name��Order��
: ͨ��table1��name��b�������Sql���Table3�е����ݣ��������Ǹ��Table2�е���Orde
: r��ӦAttr_Value�����ֽ�������
: Table3
: Attr_Value
: Mark
: .................������ʡ�ԣ�

--
�����к� sunny boy �ֻ�15900941215 [�������]��վ http://yoursunny.com/ 
�����к������ֹ� ��ֱ ���� ��� ���� �¸�

���������վ����֧���ֻ���ʣ���������ֻ� http://yoursunny.com/
��RSS����FTPĿ¼ http://www.65536.cn/work/2008/FtpFeed/

�� ��Դ:����ˮ˼Դ bbs.sjtu.edu.cn��[FROM: 2001:da8:8000:e08a:212:3fff:fe1f:5330]
Technical Details
Message-ID: <4aUBZ0$auY@bbs.sjtu.edu.cn>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!news.shec6.edu.cn!SJTU

Show Full Headers
Complete Article Headers
X-Google-Thread: 101948,d1fb83a02b625c2b,start
X-Google-Attributes: gid101948,domainid0,public,usenet
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!news.shec6.edu.cn!SJTU
From: aspx.bbs@bbs.sjtu.edu.cn (yoursunny.com)
Newsgroups: cn.bbs.comp.database
Subject: Re: ���ʵ������SQL, �����·��ָ�̰�
Date: 17 Jun 2008 00:50:35 GMT
Organization: ��ˮ˼Դ
Message-ID: <4aUBZ0$auY@bbs.sjtu.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: database/M.1213663632.A
Lines: 88