English 中文(简体)
核实MySQL的数据
原标题:Verifying Data in MySQL

我希望有人能够帮助我。 我对我的SQL很抱着新意,因此我没有完全接受它的所有能力。

我收到了一份以数据格式的电子表格:

child Name |Gender| dob| class|Parent name|parent phone|parent address

我将这3个表格分开,其中包括:

Child_details   Datatype    Required    Key
Child_id    INT AUTO_INCREMENT  NOT NULL    Primary
Child_fname VARCHAR(15)     NOT NULL     
Child_sname VARCHAR(15)     NOT NULL     
Gender  Enum(M,F) NOT NULL  NOT NULL     
DoB DATE NOT NULL   NOT NULL     
Parent/Carer id INTEGER NOT NULL    Foreign


Parent_details  Datatype    Required    Key
Parent_id   INT AUTO_INCREMENT  NOT NULL    Primary
Parent_title    CHAR(5)      
Paren _fname    VARCHAR(15)     NOT NULL     
Parent/_sname   VARCHAR(15)     NOT NULL     
Parent _Add1    VARCHAR(25)     NOT NULL     
Parent _Add2    VARCHAR(25)          
Parent _city    VARCHAR(25)          
Parent _Pcode   VARCHAR(15)     NOT NULL     
Parent _phone   VARCHAR(15)     NOT NULL     


Activity    Datatype    Required    Key
Activity_name   CHAR(8) NOT NULL     
Activity_day    CHAR(5) NOT NULL     

然后用活动数据为滚动名单提供一个过渡表。 部分儿童从事一等工作,有些则从事三类工作:

Schedule    Datatype    Required    Key
Child_id    INT NOT NULL    Foreign, Composite
Activity_id INT NOT NULL    Foreign, Composite

我试图撰写一个问题,如果我所输入的数据正确,我可以进行核查。 我想能够以与电子表格相同的格式看待结果。 这是我迄今提出的:

SELECT CONCAT_WS(   ,Child_fname,Child_sname) AS  Child Name ,
Child_gender AS  Gender ,
Child_dob AS  DoB ,
COUNT Activity_name AS Activities,
CONCAT_WS(   ,Parent_title,Parent_fname,Parent_sname) AS  Parent/Carer name ,
Parent_phone AS  Parent/Carer phone ,
CONCAT_WS(   ,Parent_add1,Parent_add2,Parent_city,Parent_pcode) AS  Parent/Carer Address 
FROM Child,Activity,Parent;

But the results I get show each child does all of the activities and that they all have each. Am I missing something obvious, do I need to use COUNT DISTINCT or GROUP BY, or have I created the tables wrong?

Any information anyone can provide would be greatly appreciated. I hope I have provided enough information, but not too much.

最佳回答

你们需要告诉我的SQL如何一起加入表格(没有这一信息,就把每张桌上的每一行与每张桌上的每一行一行一致,正如你所描述的那样):

SELECT
  ...
FROM
       Child
  JOIN Schedule USING (Child_id)
  JOIN Activity USING (Activity_id) -- does this column exist in Activity?
  JOIN Parent   USING (Parent_id)   -- does this column exist in Child?

您不妨遵循tutorials on JOIN

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签