如何编写SQL查询以检查列中的每个NAIC代码值是否为3,如果是,则对具有相同3位数NAIC代码的所有输出值求和
SELECT ni.NAICS,
ncio.outputValue,
IF( NAICS =SUBSTR(ni.NAICS,0,3), SUM(ncio.outputValue), NULL )
FROM
nwk_company_industry_output ncio,
nwk_industry ni,
nwk_company nc
WHERE
ni.NAICS = ncio.company_id
ORDER BY
NAICS
答案 0 :(得分:0)
如果连接条件正确,这应该适合您(ni.NAICS = ncio.company_id)
<?php
session_start();
$singer_name = ($_POST['singer_name']);
$song_name = ($_POST['song_name']);
$ctg_name = ($_POST['ctg_name']);
$mp3 = ($_POST['mp3']);
$album_cover = ($_POST['album_cover']);
$link = mysqli_connect("example.com", "user", "pass", "example");
$sql = "INSERT INTO song (singer_name, song_name, ctg_name, mp3, album_cover)
VALUES ('$insertsinger_name, $insertsong_name, $insertctg_name, $insertmp3, $insertalbum_cover')";
if(mysqli_query($link, $sql)){
mysqli_close($link);
session_write_close();
header("location: songadmin.php");
exit();
} else{
die("Query Failed");
}
?>