SELECT
rht_goods.id, (
SELECT
count(rht_quality_test.id)
FROM
rht_quality_test
WHERE
rht_goods.id = rht_quality_test.pid
) num
FROM
rht_goods
表結構
CREATE TABLE `rht_goods` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`pid` int(10) unsigned DEFAULT '0' COMMENT '上市商品表id',
`title` varchar(100) DEFAULT '' COMMENT '標題',
`cat_id` int(11) DEFAULT '0' COMMENT '分類id',
`cat_name` varchar(50) DEFAULT '' COMMENT '分類名稱',
`brand_id` int(11) DEFAULT '0' COMMENT '品牌id',
`brand` varchar(50) DEFAULT '' COMMENT '品牌名稱',
`goods_no` varchar(50) DEFAULT '' COMMENT '人工創建編碼',
`pro_no` varchar(50) DEFAULT '' COMMENT '系統產品編號',
`pro_name` varchar(50) DEFAULT '' COMMENT '產品名稱',
`pro_spec` varchar(50) DEFAULT '' COMMENT '規格名稱',
`pro_spec_id` int(11) DEFAULT '0' COMMENT '規格id',
`supplier_name` varchar(100) DEFAULT '' COMMENT '生產廠家名稱(供應商)',
`supplier_no` varchar(20) DEFAULT '' COMMENT '生產廠家編號',
`operative_norm` varchar(255) DEFAULT '' COMMENT '執行標準',
`barcode_ownership` varchar(255) DEFAULT '' COMMENT '條碼歸屬',
`is_anti_fake` tinyint(4) unsigned DEFAULT '0' COMMENT '是否需要方位貼 0否 1是',
`pro_components` varchar(255) DEFAULT '' COMMENT '產品組件構成',
`three_sides` varchar(255) DEFAULT '' COMMENT '三方檢測項目',
`platemaking_cost` varchar(50) DEFAULT '' COMMENT '製版費',
`mold_cost` varchar(50) DEFAULT '' COMMENT '開模費',
`initial_ordernum` int(11) unsigned DEFAULT '0' COMMENT '首批訂貨量',
`minmum_order_quantity` int(11) unsigned DEFAULT '0' COMMENT '最低起訂量',
`approval_sales_price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '報批銷售價',
`retail_price` decimal(10,2) DEFAULT '0.00' COMMENT '報批零售價',
`supplier_cost` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '廠家供應價',
`billing_rate` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '關聯交易價',
`connect_sales_price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '銷售結算價',
`clearing_price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '經銷定製價',
`is_del` tinyint(4) unsigned DEFAULT '0' COMMENT '是否撤回 0未刪除 1已刪除',
`create_time` int(11) unsigned DEFAULT '0' COMMENT '創建時間',
`update_time` int(11) unsigned DEFAULT '0' COMMENT '修改時間',
`create_time_auto` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '自動創建時間',
`update_time_auto` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '自動修改時間',
`component_pic` text COMMENT '組件終稿圖',
`accessory` varchar(200) DEFAULT '' COMMENT '組件表',
`design_pic` text COMMENT '效果圖',
`remark` varchar(255) DEFAULT '' COMMENT '備註',
`unit` varchar(50) DEFAULT '' COMMENT '單位',
`barcode` varchar(255) DEFAULT '' COMMENT '條碼',
`permit_no` varchar(100) DEFAULT '' COMMENT '批准文號',
`user_id` int(11) DEFAULT '0' COMMENT '創建人id',
`user_name` varchar(100) DEFAULT '' COMMENT '創建人',
`one_dealer_price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '一級經銷價',
`two_dealer_price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '二級經銷價',
`weight` varchar(50) CHARACTER SET utf16le DEFAULT '' COMMENT '重量',
`len` varchar(50) DEFAULT '' COMMENT '長',
`width` varchar(50) DEFAULT '' COMMENT '寬',
`height` varchar(50) DEFAULT '' COMMENT '高',
`volume` varchar(50) DEFAULT '' COMMENT '體積',
`sales_channel` varchar(50) DEFAULT '' COMMENT '銷售渠道:1電商品,2定製分銷,3其他',
`pro_cate` varchar(50) DEFAULT '' COMMENT '生產類別',
`carton_size` int(11) DEFAULT NULL COMMENT '箱規',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=543 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='正式產品表';
表結構
CREATE TABLE `rht_quality_test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '主鍵',
`file_name` varchar(255) DEFAULT '' COMMENT '文件名',
`pid` int(11) DEFAULT NULL COMMENT '關聯物料表id',
`pic` text COMMENT '圖片文件路徑',
`create_time` int(11) DEFAULT NULL COMMENT '時間戳格式創建時間',
`update_time` int(11) DEFAULT NULL COMMENT '時間戳格式更新時間',
`create_time_auto` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '系統創建時間',
`update_time_auto` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '系統更新時間',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;